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

@loopback/build: lb-eslint throws "Package subpath './bin/eslint' is not defined by 'exports'" when in npm workspaces environment #9703

Open
shubhamp-sf opened this issue Jun 28, 2023 · 8 comments
Labels

Comments

@shubhamp-sf
Copy link
Contributor

shubhamp-sf commented Jun 28, 2023

Describe the bug

Running lb-eslint command from a package in npm workspaces environment throws following error:

Full Command: lb-eslint --report-unused-disable-directives .

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './bin/eslint' is not defined by "exports" in /Users/shubham.prajapat/repos/my-mono-repo/node_modules/eslint/package.json

Logs

loopback:build /Users/shubham.prajapat/repos/sourcefuse/loopback4-microservice-catalog/packages/cache/.eslintrc.js found +0ms
  loopback:build /Users/shubham.prajapat/repos/sourcefuse/loopback4-microservice-catalog/packages/cache/.eslintignore found +1ms
  loopback:build Trying to resolve CLI module 'eslint' from /Users/shubham.prajapat/repos/sourcefuse/loopback4-microservice-catalog/packages/cache +0ms
  loopback:build CLI module 'eslint' is not found in dependencies +0ms
node:internal/modules/cjs/loader:571
      throw e;
      ^

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './bin/eslint' is not defined by "exports" in /Users/shubham.prajapat/repos/sourcefuse/loopback4-microservice-catalog/node_modules/eslint/package.json
    at new NodeError (node:internal/errors:399:5)
    at exportsNotFound (node:internal/modules/esm/resolve:361:10)
    at packageExportsResolve (node:internal/modules/esm/resolve:697:9)
    at resolveExports (node:internal/modules/cjs/loader:565:36)
    at Module._findPath (node:internal/modules/cjs/loader:634:31)
    at Module._resolveFilename (node:internal/modules/cjs/loader:1061:27)
    at Function.resolve (node:internal/modules/cjs/helpers:116:19)
    at resolveCLI (/Users/shubham.prajapat/repos/sourcefuse/loopback4-microservice-catalog/node_modules/@loopback/build/bin/utils.js:76:18)
    at Object.runCLI (/Users/shubham.prajapat/repos/sourcefuse/loopback4-microservice-catalog/node_modules/@loopback/build/bin/utils.js:128:9)
    at run (/Users/shubham.prajapat/repos/sourcefuse/loopback4-microservice-catalog/node_modules/@loopback/build/bin/run-eslint.js:45:16) {
  code: 'ERR_PACKAGE_PATH_NOT_EXPORTED'
}

Node.js v18.16.0

Additional information

Screenshot 2023-06-28 at 7 13 30 PM

Reproduction

https://codesandbox.io/p/github/shubhamp-sf/eslint-17321-reproduction/main

@shubhamp-sf
Copy link
Contributor Author

I tried adding this line in eslint's package json and it worked. But not sure if it's the right solution and how do I patch this for everyone in the team.

Raised this on their repo too: eslint/eslint#17321

{
  "name": "eslint",
  "version": "8.43.0",
  "bin": {
    "eslint": "./bin/eslint.js"
  },
  "main": "./lib/api.js",
  "exports": {
    "./package.json": "./package.json",
+    "./bin/eslint": "./bin/eslint.js",
    ".": "./lib/api.js",
    "./use-at-your-own-risk": "./lib/unsupported-api.js"
  },
  ...

@shubhamp-sf
Copy link
Contributor Author

@frbuceta can you please check this issue.

This will block all of our projects using LoopBack from using npm workspaces.

@frbuceta
Copy link
Contributor

frbuceta commented Jul 9, 2023

@frbuceta can you please check this issue.

This will block all of our projects using LoopBack from using npm workspaces.

The command is not failing me... I will check it tomorrow with more time.

@shubhamp-sf
Copy link
Contributor Author

The command is not failing me... I will check it tomorrow with more time.

Thanks, You can refer the reproduction code I've mentioned in the issue comment at the top.

Or try running: npm run eslint --workspaces --if-present in loopback-next repo.
This is what it throws for me: https://app.warp.dev/block/wDqY06LLDmpRBNBH1VmeL6

@frbuceta
Copy link
Contributor

The command is not failing me... I will check it tomorrow with more time.

Thanks, You can refer the reproduction code I've mentioned in the issue comment at the top.

Or try running: npm run eslint --workspaces --if-present in loopback-next repo. This is what it throws for me: https://app.warp.dev/block/wDqY06LLDmpRBNBH1VmeL6

Try the changes I made in this branch... https://github.com/loopbackio/loopback-next/tree/frbuceta/fix-exports-eslint

@shubhamp-sf
Copy link
Contributor Author

shubhamp-sf commented Jul 16, 2023

The changes worked for npm workspaces, Thanks @frbuceta!

I didn't try with lerna though. But based on the code changes I see there shouldn't be any issue on that too IMO.

Can we have these applied in the actual @loopback/build package?

@Graunephar
Copy link

I can see that I have the same issue. Did this find its way t @loopback/build package or are we waiting for that still ? :)

@Graunephar
Copy link

I still have exactly the same issue.

@frbuceta did these changes make it into @loopback/build yet?

Currently this issue blocks us from runnings tests in pipelines. I have tried upgrading every package related to this, but still get the same issue.

When i run yarn run lb-eslint I get

  ^

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './bin/eslint' is not defined by "exports" in /Users/daniel/Git/welcomebob-admin/node_modules/eslint/package.json
    at new NodeError (node:internal/errors:372:5)
    at throwExportsNotFound (node:internal/modules/esm/resolve:440:9)
    at packageExportsResolve (node:internal/modules/esm/resolve:719:3)
    at resolveExports (node:internal/modules/cjs/loader:483:36)
    at Module._findPath (node:internal/modules/cjs/loader:523:31)
    at Module._resolveFilename (node:internal/modules/cjs/loader:925:27)
    at Function.resolve (node:internal/modules/cjs/helpers:108:19)
    at resolveCLI (/Users/daniel/Git/welcomebob-admin/node_modules/@loopback/build/bin/utils.js:76:18)
    at Object.runCLI (/Users/daniel/Git/welcomebob-admin/node_modules/@loopback/build/bin/utils.js:128:9)
    at run (/Users/daniel/Git/welcomebob-admin/node_modules/@loopback/build/bin/run-eslint.js:45:16) {
  code: 'ERR_PACKAGE_PATH_NOT_EXPORTED'
}

Node.js v18.0.0

The same fix described by #9703 (comment) also fixes the problem for me. But thats of course not a viable long term option

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants