Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

import("eslint") doesn't work #8

Closed
mdjermanovic opened this issue Dec 16, 2021 · 1 comment · Fixed by #9
Closed

import("eslint") doesn't work #8

mdjermanovic opened this issue Dec 16, 2021 · 1 comment · Fixed by #9
Assignees
Labels

Comments

@mdjermanovic
Copy link
Member

With npx @eslint/create-config command, import("eslint") doesn't work because it can't resolve "eslint" from a location within npm-cache where @eslint/create-config gets installed. It looks like we need to find a way to resolve "eslint" relative to cwd.

$ npx @eslint/create-config
npx: installed 40 in 10.142s
√ How would you like to use ESLint? · syntax
√ What type of modules does your project use? · none
√ Which framework does your project use? · none
√ Does your project use TypeScript? · No / Yes
√ Where does your code run? · No items were selected
√ What format do you want your config file to be in? · JavaScript
Local ESLint installation not found.
The config that you've selected requires the following dependencies:

eslint@latest
√ Would you like to install them now with npm? · No / Yes
Installing eslint@latest
+ [email protected]
added 88 packages from 56 contributors and audited 88 packages in 11.58s

13 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities

(node:4980) UnhandledPromiseRejectionWarning: Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'eslint' imported from C:\Users\MILOS\AppData\Roaming\npm-cache\_npx\4980\node_modules\@eslint\create-config\lib\init\config-file.js
    at packageResolve (internal/modules/esm/resolve.js:664:9)
    at moduleResolve (internal/modules/esm/resolve.js:705:18)
    at Loader.defaultResolve [as _resolve] (internal/modules/esm/resolve.js:798:11)
    at Loader.resolve (internal/modules/esm/loader.js:100:40)
    at Loader.getModuleJob (internal/modules/esm/loader.js:246:28)
    at Loader.import (internal/modules/esm/loader.js:181:28)
    at importModuleDynamically (internal/modules/esm/translators.js:109:35)
    at exports.importModuleDynamicallyCallback (internal/process/esm_loader.js:32:14)
    at writeJSConfigFile (file:///C:/Users/MILOS/AppData/Roaming/npm-cache/_npx/4980/node_modules/@eslint/create-config/lib/init/config-file.js:88:24)
    at Module.write (file:///C:/Users/MILOS/AppData/Roaming/npm-cache/_npx/4980/node_modules/@eslint/create-config/lib/init/config-file.js:119:19)
(node:4980) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:4980) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
@aladdin-add
Copy link
Member

An inelegant fix would be:

const eslint = await import(path.join(cwd, "./node_modules/eslint/lib/api.js"));

but it's not always safe, as the "/lib/api.js" may be changed in future changes, and not works for yarn pnp.

aladdin-add added a commit that referenced this issue Dec 16, 2021
@nzakas nzakas closed this as completed in #9 Dec 18, 2021
nzakas added a commit that referenced this issue Dec 18, 2021
* fix: import("eslint") doesn't work

fixes #8

* fix: failing tests

* fix: safer import

* Update lib/init/config-file.js

Co-authored-by: Nicholas C. Zakas <[email protected]>

Co-authored-by: Nicholas C. Zakas <[email protected]>
@nzakas nzakas moved this to Complete in Triage Jan 3, 2023
@nzakas nzakas added this to Triage Jan 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants