loopback-next icon indicating copy to clipboard operation
loopback-next copied to clipboard

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

Open shubhamp-sf opened this issue 1 year ago • 8 comments

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 avatar Jun 28 '23 13:06 shubhamp-sf

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: https://github.com/eslint/eslint/issues/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 avatar Jun 30 '23 06:06 shubhamp-sf

@frbuceta can you please check this issue.

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

shubhamp-sf avatar Jul 08 '23 16:07 shubhamp-sf

@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.

frbuceta avatar Jul 09 '23 22:07 frbuceta

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

shubhamp-sf avatar Jul 10 '23 02:07 shubhamp-sf

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

frbuceta avatar Jul 14 '23 09:07 frbuceta

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?

shubhamp-sf avatar Jul 16 '23 12:07 shubhamp-sf

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 avatar Aug 03 '23 12:08 Graunephar

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 https://github.com/loopbackio/loopback-next/issues/9703#issuecomment-1614190690 also fixes the problem for me. But thats of course not a viable long term option

Graunephar avatar Dec 04 '23 14:12 Graunephar