Skip to content

rspack-resolver was breaking change #405

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

Closed
pckilgore opened this issue Mar 25, 2025 · 26 comments
Closed

rspack-resolver was breaking change #405

pckilgore opened this issue Mar 25, 2025 · 26 comments

Comments

@pckilgore
Copy link

As of a recent version upgrade using rspack-resolver, the no-restricted-paths lint is breaks. Previously no native code was required to be run.

  1:1  error  Resolve error: Failed to load native binding
    at Object.<anonymous> (/Users/kilgore/gravity/monorepo/src/www/node_modules/rspack-resolver/index.js:368:11)
    at Module._compile (node:internal/modules/cjs/loader:1546:14)
    at Object..js (node:internal/modules/cjs/loader:1689:10)
    at Module.load (node:internal/modules/cjs/loader:1318:32)
    at Function._load (node:internal/modules/cjs/loader:1128:12)
    at TracingChannel.traceSync (node:diagnostics_channel:315:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:218:24)
    at Module.require (node:internal/modules/cjs/loader:1340:12)
    at require (node:internal/modules/helpers:141:16)
    at Object.<anonymous> (/Users/kilgore/gravity/monorepo/src/www/node_modules/eslint-import-resolver-typescript/lib/index.cjs:6:22)  import/no-restricted-paths
@pckilgore
Copy link
Author

pckilgore commented Mar 25, 2025

Misread this dep as in the recent patch version, but I see now added in v4.

I suppose everything is about tradeoffs, but as a data point, the speed improvement here was minuscule (completely unnoticeable in a very very large codebase) but the new lack environment agnosticism is deeply annoying.

@JounQin
Copy link
Collaborator

JounQin commented Mar 26, 2025

What platform are you using? We'll target more platforms recently.

@JounQin
Copy link
Collaborator

JounQin commented Mar 26, 2025

Please help to try [email protected] which adds new 4 targets support:

  • i686-pc-windows-msvc
  • armv7-unknown-linux-musleabihf
  • powerpc64le-unknown-linux-gnu
  • s390x-unknown-linux-gnu

@pckilgore
Copy link
Author

pckilgore commented Mar 26, 2025 via email

@JounQin
Copy link
Collaborator

JounQin commented Mar 26, 2025

It replaces slow enhanced-resolve, not a javascript interpreter, it's much faster.

Not to mention the supply chain / security concerns shipping compiled binaries raises.

It's open sourced at https://github.com/unrs/unrs-resolver

All releases are provenanced:

https://www.npmjs.com/package/unrs-resolver

Image

@JounQin
Copy link
Collaborator

JounQin commented Mar 26, 2025

By the way, there are a lot of frontend toolchains built on top of rust/napi-rs nowdays.

  • rspack
  • oxc
  • biome
  • rolldown
  • farm
  • ...

And don't forget the new typescript-go.

@pckilgore
Copy link
Author

pckilgore commented Mar 26, 2025 via email

@JounQin
Copy link
Collaborator

JounQin commented Mar 26, 2025

That's why it's a major v4 version?

For performance, are you using eslint-plugin-import or eslint-plugin-import-x?

The v3 resolver interface of https://github.com/un-ts/eslint-plugin-import-x would provide much better performance in case you didn't know.

// eslint.config.js, CommonJS is also supported
import { createTypeScriptImportResolver } from 'eslint-import-resolver-typescript'

export default [
  {
    settings: {
      'import-x/resolver-next': [
        createTypeScriptImportResolver({
          alwaysTryTypes: true, // always try to resolve types under `<root>@types` directory even it doesn't contain any source code, like `@types/unist`

          bun: true, // resolve Bun modules https://github.com/import-js/eslint-import-resolver-typescript#bun

          // Choose from one of the "project" configs below or omit to use <root>/tsconfig.json or <root>/jsconfig.json by default

          // use <root>/path/to/folder/tsconfig.json or <root>/path/to/folder/jsconfig.json
          project: 'path/to/folder',

          // Multiple tsconfigs/jsconfigs (Useful for monorepos, but discouraged in favor of `references` supported)

          // use a glob pattern
          project: 'packages/*/{ts,js}config.json',

          // use an array
          project: [
            'packages/module-a/tsconfig.json',
            'packages/module-b/jsconfig.json',
          ],

          // use an array of glob patterns
          project: [
            'packages/*/tsconfig.json',
            'other-packages/*/jsconfig.json',
          ],
        }),
      ],
    },
  },
]

There are also users feedback positive performance improve like #376 (comment)

I'd love to but can't help with your personally workspace for performance without reproduction.

@jgable
Copy link

jgable commented Apr 2, 2025

I am also being affected by this rspack-resolver dependency issue out of nowhere. The error is extremely unhelpful, I'm glad that @pckilgore created this issue or I just would have thought some weird native binding issue was happening in my Github CI workflow.

That's why it's a major v4 version?

"dependencies": {
"@nolyfill/is-core-module": "1.0.39",
"debug": "^4.4.0",
"get-tsconfig": "^4.10.0",
"is-bun-module": "^1.3.0",
"rspack-resolver": "^1.1.0",
"stable-hash": "^0.0.5",
"tinyglobby": "^0.2.12"
},

@JounQin This dependency change was published in 3.9.1, not a major v4 version. Since eslint-config-next specifies "eslint-import-resolver-typescript": "^3.5.2", we are encountering this issue. It's likely this is also affecting a bunch of other Next.js builds.

I was able to fix this by overriding the dependency in my package.json back to 3.5.2

"eslint-import-resolver-typescript": "3.5.2",

There is probably a later version that will also work but I haven't tried.

@JounQin
Copy link
Collaborator

JounQin commented Apr 2, 2025

@jgable Sorry for this first, but that doesn't mean to be a breaking change, we still support v3.x, would you like to raise a new issue with reproduction?

By the way, what's the unhelpful error exactly?

@jgable
Copy link

jgable commented Apr 3, 2025

I will work on a repro today. This is happening on a Github action running on ubuntu-latest with Next 14 -> eslint-config-next.

The unhelpful error is Failed to load native binding in unrs-resolver.

I've tried specifying --os and --cpu but nothing is working and there are no directions to remedy so I've reverted.

@JounQin
Copy link
Collaborator

JounQin commented Apr 3, 2025

@jgable That seems a new target, please provide more arch/platform info.

@ckifer
Copy link

ckifer commented Apr 16, 2025

also facing this issue with the same error on Amazon Linux 2

Error is

Oops! Something went wrong! :(
ESLint: 9.16.0
Error: Failed to load native binding
Occurred while linting /local/p4clients/pkgbuild-const/workspace/src/<redacted>/test/client.test.ts:1
Rule: "import/namespace"
    at Object.<anonymous> (/local/p4clients/pkgbuild-const/workspace/src//<redacted>/node_modules/unrs-resolver/index.js:372:11)
    at Module._compile (node:internal/modules/cjs/loader:1469:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1548:10)
    at Module.load (node:internal/modules/cjs/loader:1288:32)
    at Module._load (node:internal/modules/cjs/loader:1104:12)
    at Module.require (node:internal/modules/cjs/loader:1311:19)
    at require (node:internal/modules/helpers:179:18)
    at Object.<anonymous> (/local/p4clients/pkgbuild-const/<redacted>/src/<redacted>/node_modules/eslint-import-resolver-typescript/lib/index.cjs:12:20)
    at Module._compile (node:internal/modules/cjs/loader:1469:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1548:10) 

@JounQin
Copy link
Collaborator

JounQin commented Apr 16, 2025

@ckifer Could be provide more useful info by debugging https://unpkg.com/[email protected]/index.js?

And in the meantime, you can use the wasi version for workaround by overrides(npm, pnpm) or resolutions(pnpm, yarn):

{
  "overrides": {
    "unrs-resolver": "npm:@unrs/resolver-binding-wasm32-wasi@latest"
  }
}

cc @jgable

@ckifer
Copy link

ckifer commented Apr 16, 2025

@JounQin thanks! For now we just downgraded to 3.9.0. The update to 3.10.0 is what breaks us https://github.com/import-js/eslint-import-resolver-typescript/releases/tag/v3.10.0 (moving to unrs-resolver)

Is there anything specific I should look for while debugging unrs-resolver? What is helpful to you?

@JounQin
Copy link
Collaborator

JounQin commented Apr 16, 2025

Is there anything specific I should look for while debugging unrs-resolver? What is helpful to you?

Yeah, first we need to know what your expected target platform by adding some logging to check in which condition it fails.

@ckifer
Copy link

ckifer commented Apr 16, 2025

@JounQin process.platform is linux, x64, isMusl is false

nativeBinding is always undefined, loaderErrors are:

Error: Cannot find module './resolver.linux-x64-gnu.node'
Error: Cannot find module '@unrs/resolver-binding-linux-x64-gnu'

I set NAPI_RS_FORCE_WASI to true and then:

Error: Cannot find module '@unrs/resolver-binding-wasm32-wasi'
Error: Cannot find module './resolver.wasi.cjs'

To me it just seems like the optionalDependencies in unrs-resolver are, in fact, not optional? and you need to install the binding you need?

@JounQin
Copy link
Collaborator

JounQin commented Apr 16, 2025

I set NAPI_RS_FORCE_WASI to true and then

They are all optional, because a correct platform/target related package will be installed automatically normally, but with NAPI_RS_FORCE_WASI you'll need to install @unrs/resolver-binding-wasm32-wasi specifically.

@JounQin
Copy link
Collaborator

JounQin commented Apr 16, 2025

What if you install @unrs/resolver-binding-linux-x64-gnu manually?

@ckifer
Copy link

ckifer commented Apr 16, 2025

Works like a charm if I install it manually

nativebinding {
  EnforceExtension: { Auto: 0, Enabled: 1, Disabled: 2 },
  sync: [Function: sync],
  ResolveTask: [Function: ResolveTask],
  ResolverFactory: [Function: ResolverFactory]
}

but I also need to build it on MacOS which fails with

npm ERR! notsup Unsupported platform for @unrs/[email protected]: wanted {"os":"linux","arch":"x64"} (current: {"os":"darwin","arch":"arm64"})

@JounQin
Copy link
Collaborator

JounQin commented Apr 16, 2025

@ckifer So that means you package manager doesn't install @unrs/resolver-binding-linux-x64-gnu automatically for you, which package manager you're using and what if by switching to yarn v2+ or pnpm?

npm ERR!

It seems npm then, could you also try the latest npm with npm i -g npm and without manual installation?

@ckifer
Copy link

ckifer commented Apr 17, 2025

Hmm I can't install the latest node and I can't use other package managers because this is company internal, I can only install up to 10.x but I'll try that

@pckilgore
Copy link
Author

I'm about to unsub from this, but hey @ckifer, appreciate your work on recharts. We've been fine since downgrading to a version that runs with just a node interpreter.

    "eslint-import-resolver-typescript": "3.8.7",

@JounQin
Copy link
Collaborator

JounQin commented Apr 17, 2025

Yeah, a think a new issue for this makes sense. @ckifer

@ckifer
Copy link

ckifer commented Apr 17, 2025

Sorry for the notifications @pckilgore! Will probably end up just doing the same at this point 🙃. Agree with your thoughts above on this. And thanks for the shoutout 🙌🏼

@JounQin with npm 10.x I get the same errors

@import-js import-js locked as resolved and limited conversation to collaborators Apr 17, 2025
@JounQin
Copy link
Collaborator

JounQin commented Apr 17, 2025

In the meantime, you can use NAPI_RS_FORCE_WASI=true and install @unrs/resolver-binding-wasm32-wasi manually.

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

No branches or pull requests

4 participants