Skip to content
This repository was archived by the owner on Aug 7, 2023. It is now read-only.
This repository was archived by the owner on Aug 7, 2023. It is now read-only.

Question: Error: Cannot find module '/package.json'  #13

@brettz9

Description

@brettz9

Hi,

Very excited to have this tool available. Thanks so much!

Issue Type

Question

Issue Description

I don't know if you'd consider this a bug, but wondering if you might know how to resolve, being more familiar with the Atom environment.

In my linting config (eslint-config-ash-nazg), I dynamically detect the ecmaVersion and env for my .eslintrc.cjs based on the minimum version of the node subfield of package.json engines so as to avoid the need for manually setting them.

With this code, I was using process.cwd() (process.cwd() helps the code work from the command line) to try to find the project root (and then package.json within that), but the base path it returns is /. I then tried the following:

typeof atom === 'undefined'
              ? process.cwd()
              : (atom?.workspace?.getCenter()?.paneContainer?.activePane?.activeItem?.getDirectoryPath() || process.cwd())

But the path is apparently not being found (same result if I remove the optional chaining operators). This code, even with the atom-specific code, appears to still be returning /.

Any idea if it is possible for me to detect (or for you to set any properties I can detect) the root directory of the current file's project?

I am using pnpm, which can theoretically change path discovery, but I wouldn't think that would affect Atom's discovery.

Thanks!

Bug Checklist

  • Restart Atom
  • Verify the eslint CLI gives the proper result, while linter-eslint-node does not
  • Paste the output of the Linter Eslint Node: Debug command from the Command Palette below
Linter Eslint Node: Debug output here

Cannot read config file: /Users/brett/eslint-config-ash-nazg/rc.js Error: Cannot find module '/package.json' Require stack:

/Users/brett/eslint-config-ash-nazg/rc.js
/Users/brett/jsdoccomment/node_modules/.pnpm/@eslint+eslintrc@[1]().2.1/node_modules/@eslint/eslintrc/dist/eslintrc.cjs
/Users/brett/jsdoccomment/node_modules/.pnpm/[email protected].[0]()/node_modules/eslint/lib/cli-engine/cli-engine.js
[/Users/brett/jsdoccomment/node_modules/.pnpm/[email protected]](mailto:/Users/brett/jsdoccomment/node_modules/.pnpm/[email protected])/node_modules/eslint/lib/eslint/eslint.js
[/Users/brett/jsdoccomment/node_modules/.pnpm/[email protected]](mailto:/Users/brett/jsdoccomment/node_modules/.pnpm/[email protected])/node_modules/eslint/lib/eslint/index.js
[/Users/brett/jsdoccomment/node_modules/.pnpm/[email protected]](mailto:/Users/brett/jsdoccomment/node_modules/.pnpm/[email protected])/node_modules/eslint/lib/api.js
[/Users/brett/jsdoccomment/node_modules/.pnpm/[email protected]](mailto:/Users/brett/jsdoccomment/node_modules/.pnpm/[email protected])/node_modules/eslint/lib/api.js Referenced from: /Users/brett/eslint-config-ash-nazg/sauron-node-overrides.js
linter-eslint-node debug information

Atom version: 1.60.0
linter-eslint-node version: 1.0.3
Worker using Node at path: /Users/brett/.nvm/versions/node/v14.17.1/bin/node
Worker Node version: v14.17.1
Worker PID: 81288
ESLint version: 8.11.0
ESLint location: [/Users/brett/jsdoccomment/node_modules/.pnpm/[email protected]](mailto:/Users/brett/jsdoccomment/node_modules/.pnpm/[email protected])/node_modules/eslint/
Linting in this project performed by: linter-eslint-node
Hours since last Atom restart: 0.1
Platform: darwin
Current file's scopes: [
  "source.js"
]
linter-eslint-node configuration: {
  "disabling": {
    "disableWhenNoEslintConfig": false,
    "rulesToSilenceWhileTyping": []
  },
  "scopes": [
    "source.js",
    "source.jsx",
    "source.js.jsx",
    "source.flow",
    "source.babel",
    "source.js-semantic",
    "source.ts"
  ],
  "nodeBin": "node",
  "warnAboutOldEslint": true,
  "autofix": {
    "fixOnSave": false,
    "rulesToDisableWhileFixing": [],
    "ignoreFixableRulesWhileTyping": false
  },
  "advanced": {
    "disableEslintIgnore": false,
    "showRuleIdInMessage": true,
    "useCache": true
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions