Skip to content

Lookup crashes when module is not in project root. #89

Description

@phyllisstein

Just flagging that this turns out to be a little too direct a lookup technique:

const nodeModulePath = path.normalize(`${projectPath}/node_modules/${importModule}`);
const mainfile = getMainFileName(nodeModulePath);

It was crashing for me in a monorepo, where the folder structure looks something like this:

.
├── node_modules
├── packages
│   ├── astriflammante
│   │   ├── node_modules
│   │   └── package.json
│   ├── crane
│   │   ├── node_modules
│   │   └── package.json
│   ├── empire
│   │   ├── node_modules
│   │   └── package.json
│   ├── marilyn
│   │   ├── node_modules
│   │   └── package.json
│   ├── sarastro
│   │   ├── node_modules
│   │   └── package.json
│   └── wendy
│       ├── node_modules
│       └── package.json
└── package.json

If I was working in wendy and importing something from react, the package would crash trying to read a nonexistent ./node_modules/react/package.json instead of ./packages/wendy/node_modules/react/package.json:

Uncaught (in promise) Error: ENOENT: no such file or directory, open '/Users/daniel/Repos/Bauer/oedipus/node_modules/react/package.json'
    at Object.fs.openSync (fs.js:558:18)
    at Object.module.(anonymous function) [as openSync] (ELECTRON_ASAR.js:173:20)
    at Object.fs.readFileSync (fs.js:468:33)
    at Object.fs.readFileSync (ELECTRON_ASAR.js:506:29)
    at getMainFileName (/Users/daniel/Repos/Personal/Forks/atom-autocomplete-modules/src/utils/export-module-completion.js:58:22)
    at parseModule.then.results (/Users/daniel/Repos/Personal/Forks/atom-autocomplete-modules/src/utils/export-module-completion.js:52:24)

Kind of an edge case, but might be worth at least wrapping in a try...catch block to keep it from crashing other autocompletion modules.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions