Comments (38)
All, my mistake i added the node_modules folder to the ignore property in .flowconfig
, I removed it and everything worked.
from flow.
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.
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.
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.
@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.
Similar problem with hapi
hapi Required module not found
In their package.json file they have:
"main": "index"
from flow.
Changing "main": "index"
to "main":"index.js"
solves the issue.
@josebalius maybe you can try that with react-router too?
from flow.
@josebalius changing package.json to have the main include .js fixes this too for react-router.
from flow.
If this is resolved, can we close the issue?
from flow.
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.
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.
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.
@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.
@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.
@nnarhinen You are right with that. I just wanted to explain the flow implementation.
from flow.
@tcoopman yep that fixed the error, but flow should be able to handle this right?
from flow.
@avikchaudhuri @josebalius I believe that flow should indeed be able to handle this.
Maybe someone can add this based on #78
from flow.
@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.
from flow.
@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.
@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.
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.
@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.
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.
cc @lordhoto regression in 0.1.1?
from flow.
At least with my patch applied all the node_tests run well. I'll executed them with 'flow check --all'
from flow.
@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.
@tcoopman Yeah I am pretty sure, what's the best way to reset flow completely just in case?
from flow.
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.
I've updated my patch yesterday morning. I think its finished now.
from flow.
@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.
@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.
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.
@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.
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.
@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.
@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.
Anything on this issue ?
from flow.
Related Issues (20)
- Partial type does not accept plain empty object literal as a default HOT 5
- Cannot return class type as T: Cannot return `root(...)` because a call signature declaring the expected parameter / return type is missing in `SomeModel` [1] but exists in function type [2].Flow(prop-missing) HOT 2
- Does not narrow down type after undefined/falsy check HOT 1
- Recursive/deep Partial HOT 2
- Bugs in negated `instanceof` expressions HOT 1
- [Question]: How to fix flowgen test after flow update HOT 3
- [Discussion]: Any plans to make Flow more interpopble with TS ecosystem? HOT 5
- Higher order type parameter support HOT 1
- Readme links to 404
- Strange index signature error if you use $Keys<O> instead of the equivalent literal union inside $ReadOnlyArray HOT 1
- [homebrew] automation script needs update HOT 2
- "Unxepcted identifier, expected the token ;" when using await inside of ES module HOT 3
- Can't iterate through chars in a string HOT 4
- Flow does not catch invalid switch statements HOT 1
- Conditional type only works if I inline it HOT 5
- Object with null prototype does not extend interface {} HOT 3
- Missing documentation for "render-types"? HOT 2
- Relay + graphql literals HOT 11
- [homebrew] regression test failure with 0.226.0,0.227.0 HOT 2
- FLOW BUG: This is a misplaced error HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flow.