eslint / create-config

Utility to create ESLint config files

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

cannot import() local-installed eslint when running npm/npx

aladdin-add opened this issue · comments

➜  rract git:(main) ✗ npm init @eslint/config
✔ How would you like to use ESLint? · problems
✔ What type of modules does your project use? · esm
✔ Which framework does your project use? · react
✔ Does your project use TypeScript? · No / Yes
✔ Where does your code run? · browser✔ What format do you want your config file to be in? · JavaScript
The config that you've selected requires the following dependencies:

eslint-plugin-react@latest
✔ Would you like to install them now with npm? · No / Yes
node:internal/errors:464
    ErrorCaptureStackTrace(err);
    ^

Error [ERR_MODULE_NOT_FOUND]: An error occurred while generating your JavaScript config file. A config file was still generated, but the config file itself may not follow your linting rules.
Error: Cannot find package 'eslint' imported from /Users/weiran/.npm/_npx/7ef27be80482e586/node_modules/@eslint/create-config/lib/init/config-file.js
    at new NodeError (node:internal/errors:371:5)
    at packageResolve (node:internal/modules/esm/resolve:864:9)
    at moduleResolve (node:internal/modules/esm/resolve:910:18)
    at defaultResolve (node:internal/modules/esm/resolve:1005:11)
    at ESMLoader.resolve (node:internal/modules/esm/loader:475:30)
    at ESMLoader.getModuleJob (node:internal/modules/esm/loader:245:18)
    at ESMLoader.import (node:internal/modules/esm/loader:326:22)
    at importModuleDynamically (node:internal/modules/esm/translators:111:35)
    at importModuleDynamicallyCallback (node:internal/process/esm_loader:35:14)
    at writeJSConfigFile (file:///Users/weiran/.npm/_npx/7ef27be80482e586/node_modules/@eslint/create-config/lib/init/config-file.js:89:24) {
  code: 'ERR_MODULE_NOT_FOUND'
}

Node.js v17.2.0

as eslint was installed in cwd, while @eslint/create-config was not. The error was thrown in this line:

const eslint = (await import("eslint"));

Duplicate of #8