GithubHelp home page GithubHelp logo

Node module not recognized about flow HOT 38 CLOSED

facebook avatar facebook commented on April 20, 2024
Node module not recognized

from flow.

Comments (38)

josebalius avatar josebalius commented on April 20, 2024 1

All, my mistake i added the node_modules folder to the ignore property in .flowconfig, I removed it and everything worked.

from flow.

nnarhinen avatar nnarhinen commented on April 20, 2024

As I noticed in #48 and #49 flow is using some own implementation following requires.

It does not find modules from node_modules if I try to use some sub paths of the modules.

In an attempt to workaround #48 I removed the NODE_PATH hack and instead symlinked some directories to node_modules(like ln -s ../lib/models)

After that require('models/somemodel') makes flow complain /path/to/some/file.js ... somemodel.js Required module not found

from flow.

josebalius avatar josebalius commented on April 20, 2024

The thing is this a standard module in the node_modules folder in the same directory I ran flow init, not sure why it cannot find it.

One I noticed is that the module doesn't have an index.js but instead a dist folder

from flow.

avikchaudhuri avatar avikchaudhuri commented on April 20, 2024

Our algorithm for finding node modules basically follows the spec at: http://nodejs.org/api/modules.html

(We don't do anything special for dist.)

from flow.

josebalius avatar josebalius commented on April 20, 2024

@avikchaudhuri thanks for getting back to me, the react-router package json has the following

{
  "name": "react-router",
  "version": "0.10.2",
  "description": "A complete routing library for React.js",
  "main": "./modules/index",
  "repository": {
    "type": "git",
    "url": "https://github.com/rackt/react-router.git"
  },
  "homepage": "https://github.com/rackt/react-router/blob/latest/README.md",
  "bugs": {
    "url": "https://github.com/rackt/react-router/issues"
  },
  "directories": {
    "example": "examples"
  },

Notice the main property, (i know i said dist, but it seems to be a modules folder) is flow handling this? I'm a bit rusty on the modules spec but I will take a look and see if this is valid.

from flow.

tcoopman avatar tcoopman commented on April 20, 2024

Similar problem with hapi

hapi Required module not found

In their package.json file they have:

"main": "index"

from flow.

tcoopman avatar tcoopman commented on April 20, 2024

Changing "main": "index" to "main":"index.js" solves the issue.

@josebalius maybe you can try that with react-router too?

from flow.

tcoopman avatar tcoopman commented on April 20, 2024

@josebalius changing package.json to have the main include .js fixes this too for react-router.

from flow.

avikchaudhuri avatar avikchaudhuri commented on April 20, 2024

If this is resolved, can we close the issue?

from flow.

KnisterPeter avatar KnisterPeter commented on April 20, 2024

I have the same problem for the dat-gui package. In the package.json is no main attribute and there is an index.js file which should be used by default.
So there is still something wrong.

from flow.

KnisterPeter avatar KnisterPeter commented on April 20, 2024

The missing "main" attribute in the package.json is the problem. If I add it, then it does work.
This should be fixed since "main" is optional if there is a index.js in the root folder of the module.

from flow.

nnarhinen avatar nnarhinen commented on April 20, 2024

Also it seems if something is in node_modules flow expects it to have a package.json file This is not always the case and shouldn't be treated like that. Node is completely happy to resolve require('foo/bar/baz') to node_modules/foo/bar/baz.js

from flow.

KnisterPeter avatar KnisterPeter commented on April 20, 2024

@nnarhinen This is not entirely right. flow searches for a package.json, if there is one it only looks for the main attribute. If that is missing the resolving stops. If there is no package.json it looks for an index.js file, if that is missing the resolving fails.

from flow.

nnarhinen avatar nnarhinen commented on April 20, 2024

@KnisterPeter ok, well that's not how node works in this case. nodejs resolves foo/bar/baz just happily to node_modules/foo/bar/baz.js. that's how flow should work too, IMO.

from flow.

KnisterPeter avatar KnisterPeter commented on April 20, 2024

@nnarhinen You are right with that. I just wanted to explain the flow implementation.

from flow.

josebalius avatar josebalius commented on April 20, 2024

@tcoopman yep that fixed the error, but flow should be able to handle this right?

from flow.

tcoopman avatar tcoopman commented on April 20, 2024

@avikchaudhuri @josebalius I believe that flow should indeed be able to handle this.

Maybe someone can add this based on #78

from flow.

KnisterPeter avatar KnisterPeter commented on April 20, 2024

@tcoopman @avikchaudhuri @josebalius I could look into this later this day and extend my pull request to be more node-resolving algorithm compliant.

from flow.

tcoopman avatar tcoopman commented on April 20, 2024

@KnisterPeter 👍

from flow.

KnisterPeter avatar KnisterPeter commented on April 20, 2024

@avikchaudhuri @tcoopman @josebalius The pull request is extended with cases adding '.js' to the required path if no other resolution is found.
But I guess the code needs a review, because I'm not an expert on OCaml 😄

from flow.

josebalius avatar josebalius commented on April 20, 2024

@KnisterPeter thanks! keen to try it. I just upgraded to the new version, and it seems that @tcoopman's solution doesn't work anymore :(

from flow.

KnisterPeter avatar KnisterPeter commented on April 20, 2024

Which exactly do you mean? There are the node_tests which should contain all possible solutions. Which one is failing? Or which one is missing?

from flow.

josebalius avatar josebalius commented on April 20, 2024

@KnisterPeter your PR hasn't been merged yet, so I am pretty sure it's not your solution, but whatever code they push for the 0.1.1 release doesn't pick up any of my modules :(

from flow.

josebalius avatar josebalius commented on April 20, 2024

Seeing this

client/routes.js:5:13,28: react.js
Required module not found

client/routes.js:6:14,36: index.js
Required module not found

Which comes from:

var React = require('react');
var Router = require('react-router');

Each of those modules have a main property in their package.json but for some reason in 0.1.1 flow can't find it. It was able to find react in 0.1.0, and I gotten react-router to work by adding .js to the main property, but none of them work at the moment for me.

from flow.

avikchaudhuri avatar avikchaudhuri commented on April 20, 2024

cc @lordhoto regression in 0.1.1?

from flow.

KnisterPeter avatar KnisterPeter commented on April 20, 2024

At least with my patch applied all the node_tests run well. I'll executed them with 'flow check --all'

from flow.

tcoopman avatar tcoopman commented on April 20, 2024

@josebalius I've tested my workaround in 0.1.1 for react-router and it works for me. React is also correctly imported.

Are you sure you don't have anything else that's changed?

from flow.

josebalius avatar josebalius commented on April 20, 2024

@tcoopman Yeah I am pretty sure, what's the best way to reset flow completely just in case?

from flow.

nnarhinen avatar nnarhinen commented on April 20, 2024

Any updates on these resolving problems? For me they are a show-stopper if I can't use flow on a browserify-based application.

from flow.

KnisterPeter avatar KnisterPeter commented on April 20, 2024

I've updated my patch yesterday morning. I think its finished now.

from flow.

nnarhinen avatar nnarhinen commented on April 20, 2024

@KnisterPeter Please give me a quick brief how I can test your patch and I'll let you know how it behaves on my existing project

from flow.

KnisterPeter avatar KnisterPeter commented on April 20, 2024

@nnarhinen If you don't rely on any other latest commits you could clone my fork (the patch is in the master branch), run make to compile flow and all should be ready to run. Otherwise you just need to clone the current flow master and add my pull-request on top and then compile flow.

from flow.

nnarhinen avatar nnarhinen commented on April 20, 2024

Ok @KnisterPeter I installed your fork. Here's the result:

$ ../../opensource/flow/bin/flow 

/Users/nnarhinen/projects/myproject/src/backend/models/Model.js:5:17,44: bookshelf.js
Required module not found

/Users/nnarhinen/projects/myproject/src/backend/models/Model.js:9:20,55: index.js
Required module not found

/Users/nnarhinen/projects/myproject/src/backend/models/Model.js:10:15,45: openssl.js
Required module not found

The related requires are:

var Bookshelf = require('backend/bookshelf');
var foos = require('backend/foo/foos'); // the path is a directory
var openssl = require('backend/foo/openssl');

Output of ls -l node_modules/backend

lrwxr-xr-x  1 nnarhinen  staff  14 19 Mar 12:40 node_modules/backend -> ../src/backend

from flow.

KnisterPeter avatar KnisterPeter commented on April 20, 2024

@nnarhinen Can you please output 'ls -l node_modules/backend/' (Note the slash at the end which lists the content of the node_modules/backend folder)

from flow.

nnarhinen avatar nnarhinen commented on April 20, 2024

Relevant parts:

-rw-r--r--   1 nnarhinen  staff   176  7 Mar 06:16 bookshelf.js
drwxr-xr-x   5 nnarhinen  staff   170 24 Mar 15:13 foo

(no package.json nor index.js)

ls -l node_modules/backend/foo/

drwxr-xr-x  4 nnarhinen  staff   136 21 Mar 21:21 foos
-rw-r--r--  1 nnarhinen  staff  1189 24 Mar 15:13 openssl.js

ls -l node_modules/backend/foo/foos/

-rw-r--r--  1 nnarhinen  staff  3597 21 Mar 21:21 index.js

from flow.

KnisterPeter avatar KnisterPeter commented on April 20, 2024

@nnarhinen The require('backend/bookshelf') you do is exactly like the 'node_tests/path_node_modules' unit test which does run successful on my setup. Can you please verify if it works for you or if it fails? Use 'flow check --all' to run the test case.

from flow.

nnarhinen avatar nnarhinen commented on April 20, 2024

@KnisterPeter it's the symlinks that make it fail. I did

cd node_tests/path_node_modules
mv node_modules/bar_lib lib
cd node_modules
ln -s ../lib bar_lib
cd ..
../../bin/flow check --all

and it fails with

/Users/nnarhinen/opensource/flow/node_tests/path_node_modules/foo.js:1:9,38: bar.js
Required module not found

from flow.

cristian-sima avatar cristian-sima commented on April 20, 2024

Anything on this issue ?

from flow.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.