Galooshi / import-js

A tool to simplify importing JS modules
MIT License
525 stars 55 forks source link

Some errors with v2.1.2 #373

Open lencioni opened 7 years ago

lencioni commented 7 years ago

I just updated to v2.1.2 and am running into some issues. I'm guessing that I have a stale cache or something. In my logs I see stuff like the following:

Error: ENOENT: no such file or directory, open '/Users/joe_lencioni/airlab/repos/airbnb/node_modules/jest/build/jest-cli'
    at Error (native)
    at Object.fs.openSync (fs.js:634:18)
    at Object.fs.readFileSync (fs.js:502:33)
    at findCommonJSExports (/Users/joe_lencioni/.nvm/versions/node/v6.2.2/lib/node_modules/import-js/build/findExports.js:88:46)
    at /Users/joe_lencioni/.nvm/versions/node/v6.2.2/lib/node_modules/import-js/build/findExports.js:201:50
    at Array.forEach (native)
    at findNamedExports (/Users/joe_lencioni/.nvm/versions/node/v6.2.2/lib/node_modules/import-js/build/findExports.js:199:9)
    at findExports (/Users/joe_lencioni/.nvm/versions/node/v6.2.2/lib/node_modules/import-js/build/findExports.js:284:15)
    at /Users/joe_lencioni/.nvm/versions/node/v6.2.2/lib/node_modules/import-js/build/ModuleFinder.js:207:47
1487274183441 ERROR PID:77441 Failed to parse ./node_modules/react-addons-test-utils/index.js: ENOENT: no such file or directory, open '/Users/joe_lencioni/airlab/repos/airbnb/node_modules/react-addons-test-utils/react-dom/lib/ReactTestUtils'
Error: ENOENT: no such file or directory, open '/Users/joe_lencioni/airlab/repos/airbnb/node_modules/react-addons-test-utils/react-dom/lib/ReactTestUtils'
    at Error (native)
    at Object.fs.openSync (fs.js:634:18)
    at Object.fs.readFileSync (fs.js:502:33)
    at findCommonJSExports (/Users/joe_lencioni/.nvm/versions/node/v6.2.2/lib/node_modules/import-js/build/findExports.js:88:46)
    at /Users/joe_lencioni/.nvm/versions/node/v6.2.2/lib/node_modules/import-js/build/findExports.js:201:50
    at Array.forEach (native)
    at findNamedExports (/Users/joe_lencioni/.nvm/versions/node/v6.2.2/lib/node_modules/import-js/build/findExports.js:199:9)
    at findExports (/Users/joe_lencioni/.nvm/versions/node/v6.2.2/lib/node_modules/import-js/build/findExports.js:284:15)
    at /Users/joe_lencioni/.nvm/versions/node/v6.2.2/lib/node_modules/import-js/build/ModuleFinder.js:207:47
1487274187689 ERROR PID:77441 Failed to parse ./node_modules/react-addons-css-transition-group/index.js: ENOENT: no such file or directory, open '/Users/joe_lencioni/airlab/repos/airbnb/node_modules/react-addons-css-transition-group/react/lib/ReactCSSTransitionGroup'
Error: ENOENT: no such file or directory, open '/Users/joe_lencioni/airlab/repos/airbnb/node_modules/react-addons-css-transition-group/react/lib/ReactCSSTransitionGroup'
    at Error (native)
    at Object.fs.openSync (fs.js:634:18)
    at Object.fs.readFileSync (fs.js:502:33)
    at findCommonJSExports (/Users/joe_lencioni/.nvm/versions/node/v6.2.2/lib/node_modules/import-js/build/findExports.js:88:46)
    at /Users/joe_lencioni/.nvm/versions/node/v6.2.2/lib/node_modules/import-js/build/findExports.js:201:50
    at Array.forEach (native)
    at findNamedExports (/Users/joe_lencioni/.nvm/versions/node/v6.2.2/lib/node_modules/import-js/build/findExports.js:199:9)
    at findExports (/Users/joe_lencioni/.nvm/versions/node/v6.2.2/lib/node_modules/import-js/build/findExports.js:284:15)
    at /Users/joe_lencioni/.nvm/versions/node/v6.2.2/lib/node_modules/import-js/build/ModuleFinder.js:207:47
1487274187699 ERROR PID:77441 Failed to parse ./node_modules/react-addons-pure-render-mixin/index.js: ENOENT: no such file or directory, open '/Users/joe_lencioni/airlab/repos/airbnb/node_modules/react-addons-pure-render-mixin/react/lib/ReactComponentWithPureRenderMixin'
Error: ENOENT: no such file or directory, open '/Users/joe_lencioni/airlab/repos/airbnb/node_modules/react-addons-pure-render-mixin/react/lib/ReactComponentWithPureRenderMixin'
    at Error (native)
    at Object.fs.openSync (fs.js:634:18)
    at Object.fs.readFileSync (fs.js:502:33)
    at findCommonJSExports (/Users/joe_lencioni/.nvm/versions/node/v6.2.2/lib/node_modules/import-js/build/findExports.js:88:46)
    at /Users/joe_lencioni/.nvm/versions/node/v6.2.2/lib/node_modules/import-js/build/findExports.js:201:50
    at Array.forEach (native)
    at findNamedExports (/Users/joe_lencioni/.nvm/versions/node/v6.2.2/lib/node_modules/import-js/build/findExports.js:199:9)
    at findExports (/Users/joe_lencioni/.nvm/versions/node/v6.2.2/lib/node_modules/import-js/build/findExports.js:284:15)
    at /Users/joe_lencioni/.nvm/versions/node/v6.2.2/lib/node_modules/import-js/build/ModuleFinder.js:207:47
1487274187708 ERROR PID:77441 Failed to parse ./node_modules/react-addons-shallow-compare/index.js: ENOENT: no such file or directory, open '/Users/joe_lencioni/airlab/repos/airbnb/node_modules/react-addons-shallow-compare/react/lib/shallowCompare'
Error: ENOENT: no such file or directory, open '/Users/joe_lencioni/airlab/repos/airbnb/node_modules/react-addons-shallow-compare/react/lib/shallowCompare'
    at Error (native)
    at Object.fs.openSync (fs.js:634:18)
    at Object.fs.readFileSync (fs.js:502:33)
    at findCommonJSExports (/Users/joe_lencioni/.nvm/versions/node/v6.2.2/lib/node_modules/import-js/build/findExports.js:88:46)
    at /Users/joe_lencioni/.nvm/versions/node/v6.2.2/lib/node_modules/import-js/build/findExports.js:201:50
    at Array.forEach (native)
    at findNamedExports (/Users/joe_lencioni/.nvm/versions/node/v6.2.2/lib/node_modules/import-js/build/findExports.js:199:9)
    at findExports (/Users/joe_lencioni/.nvm/versions/node/v6.2.2/lib/node_modules/import-js/build/findExports.js:284:15)
    at /Users/joe_lencioni/.nvm/versions/node/v6.2.2/lib/node_modules/import-js/build/ModuleFinder.js:207:47
1487274187718 ERROR PID:77441 Failed to parse ./node_modules/react-addons-transition-group/index.js: ENOENT: no such file or directory, open '/Users/joe_lencioni/airlab/repos/airbnb/node_modules/react-addons-transition-group/react/lib/ReactTransitionGroup'
Error: ENOENT: no such file or directory, open '/Users/joe_lencioni/airlab/repos/airbnb/node_modules/react-addons-transition-group/react/lib/ReactTransitionGroup'
    at Error (native)
    at Object.fs.openSync (fs.js:634:18)
    at Object.fs.readFileSync (fs.js:502:33)
    at findCommonJSExports (/Users/joe_lencioni/.nvm/versions/node/v6.2.2/lib/node_modules/import-js/build/findExports.js:88:46)
    at /Users/joe_lencioni/.nvm/versions/node/v6.2.2/lib/node_modules/import-js/build/findExports.js:201:50
    at Array.forEach (native)
    at findNamedExports (/Users/joe_lencioni/.nvm/versions/node/v6.2.2/lib/node_modules/import-js/build/findExports.js:199:9)
    at findExports (/Users/joe_lencioni/.nvm/versions/node/v6.2.2/lib/node_modules/import-js/build/findExports.js:284:15)
    at /Users/joe_lencioni/.nvm/versions/node/v6.2.2/lib/node_modules/import-js/build/ModuleFinder.js:207:47
1487274187728 ERROR PID:77441 Failed to parse ./node_modules/react-addons-update/index.js: ENOENT: no such file or directory, open '/Users/joe_lencioni/airlab/repos/airbnb/node_modules/react-addons-update/react/lib/update'
Error: ENOENT: no such file or directory, open '/Users/joe_lencioni/airlab/repos/airbnb/node_modules/react-addons-update/react/lib/update'
    at Error (native)
    at Object.fs.openSync (fs.js:634:18)
    at Object.fs.readFileSync (fs.js:502:33)
    at findCommonJSExports (/Users/joe_lencioni/.nvm/versions/node/v6.2.2/lib/node_modules/import-js/build/findExports.js:88:46)
    at /Users/joe_lencioni/.nvm/versions/node/v6.2.2/lib/node_modules/import-js/build/findExports.js:201:50
    at Array.forEach (native)
    at findNamedExports (/Users/joe_lencioni/.nvm/versions/node/v6.2.2/lib/node_modules/import-js/build/findExports.js:199:9)
    at findExports (/Users/joe_lencioni/.nvm/versions/node/v6.2.2/lib/node_modules/import-js/build/findExports.js:284:15)
    at /Users/joe_lencioni/.nvm/versions/node/v6.2.2/lib/node_modules/import-js/build/ModuleFinder.js:207:47
1487274189163 ERROR PID:77441 Failed to parse ./node_modules/jest/build/jest.js: ENOENT: no such file or directory, open '/Users/joe_lencioni/airlab/repos/airbnb/node_modules/jest/build/jest-cli'
Error: ENOENT: no such file or directory, open '/Users/joe_lencioni/airlab/repos/airbnb/node_modules/jest/build/jest-cli'
    at Error (native)
    at Object.fs.openSync (fs.js:634:18)
    at Object.fs.readFileSync (fs.js:502:33)
    at findCommonJSExports (/Users/joe_lencioni/.nvm/versions/node/v6.2.2/lib/node_modules/import-js/build/findExports.js:88:46)
    at /Users/joe_lencioni/.nvm/versions/node/v6.2.2/lib/node_modules/import-js/build/findExports.js:201:50
    at Array.forEach (native)
    at findNamedExports (/Users/joe_lencioni/.nvm/versions/node/v6.2.2/lib/node_modules/import-js/build/findExports.js:199:9)
    at findExports (/Users/joe_lencioni/.nvm/versions/node/v6.2.2/lib/node_modules/import-js/build/findExports.js:284:15)
    at /Users/joe_lencioni/.nvm/versions/node/v6.2.2/lib/node_modules/import-js/build/ModuleFinder.js:207:47
1487274189348 ERROR PID:77441 Failed to parse ./node_modules/react-addons-test-utils/index.js: ENOENT: no such file or directory, open '/Users/joe_lencioni/airlab/repos/airbnb/node_modules/react-addons-test-utils/react-dom/lib/ReactTestUtils'
Error: ENOENT: no such file or directory, open '/Users/joe_lencioni/airlab/repos/airbnb/node_modules/react-addons-test-utils/react-dom/lib/ReactTestUtils'
    at Error (native)
    at Object.fs.openSync (fs.js:634:18)
    at Object.fs.readFileSync (fs.js:502:33)
    at findCommonJSExports (/Users/joe_lencioni/.nvm/versions/node/v6.2.2/lib/node_modules/import-js/build/findExports.js:88:46)
    at /Users/joe_lencioni/.nvm/versions/node/v6.2.2/lib/node_modules/import-js/build/findExports.js:201:50
    at Array.forEach (native)
    at findNamedExports (/Users/joe_lencioni/.nvm/versions/node/v6.2.2/lib/node_modules/import-js/build/findExports.js:199:9)
    at findExports (/Users/joe_lencioni/.nvm/versions/node/v6.2.2/lib/node_modules/import-js/build/findExports.js:284:15)
    at /Users/joe_lencioni/.nvm/versions/node/v6.2.2/lib/node_modules/import-js/build/ModuleFinder.js:207:47
1487274189645 ERROR PID:77441 EISDIR: illegal operation on a directory, read
1487274189645 ERROR PID:77441 EISDIR: illegal operation on a directory, read

After removing the cache and restarting importjs, I see a bunch of the following in my logs:

1487274491948 ERROR PID:78780 Failed to parse ./path/to/app/Component.jsx: Cannot read property 'name' of undefined
TypeError: Cannot read property 'name' of undefined
    at /Users/joe_lencioni/.nvm/versions/node/v6.2.2/lib/node_modules/import-js/build/findExports.js:152:19
    at Array.map (native)
    at /Users/joe_lencioni/.nvm/versions/node/v6.2.2/lib/node_modules/import-js/build/findExports.js:150:23
    at Array.forEach (native)
    at findDefinedNames (/Users/joe_lencioni/.nvm/versions/node/v6.2.2/lib/node_modules/import-js/build/findExports
.js:141:21)
    at /Users/joe_lencioni/.nvm/versions/node/v6.2.2/lib/node_modules/import-js/build/findExports.js:282:5
    at Array.forEach (native)
    at findExports (/Users/joe_lencioni/.nvm/versions/node/v6.2.2/lib/node_modules/import-js/build/findExports.js:2
81:13)
    at /Users/joe_lencioni/.nvm/versions/node/v6.2.2/lib/node_modules/import-js/build/ModuleFinder.js:207:47

The file it is failing on, looks roughly like this:

import Foo from 'foo';

const propTypes = { ... };

const defaultProps = { ... }

function Component({ aProp }) {
  return <div>...</div>;
}

Component.propTypes = propTypes;
Component.defaultProps = defaultProps;

export default withStyles(() => ({
  ...
}))(Component);
lencioni commented 7 years ago

The parse error seems to happen because of object spreading. { ...foo, ...bar }. I should be able to have a PR ready shortly.

lencioni commented 7 years ago

374 helped with the second set of errors, but I'm still seeing a number of no such file or directory errors. I'm going to ignore them for now though.

trotzig commented 7 years ago

The first set of errors seems to come from trying to follow a require from inside a node_module dependency. For jest for instance, it has a main file that does this:

module.exports = require('jest-cli');

We just assume that the require is for a local file, so we try to open the wrong path. Relevant code here: https://github.com/Galooshi/import-js/blob/9f5536319bbb5ed6d31cab74a43b05d6cc0ec9c1/lib/findExports.js#L65