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

TypeError: Can not find node binding files from @swc/core-win32-x64-gnu, @swc/core-win32-x64-msvc... #1351

Closed
tw-360vier opened this issue Jan 22, 2021 · 19 comments · Fixed by #7965
Labels

Comments

@tw-360vier
Copy link

Describe the bug
We've been using swc on linux and os x machines for a while.
Now a colleague tried to build a project on windows and encountered this error:

 C:\Users\xyz\projects\swc-win32> yarn swc
yarn run v1.22.5
$ C:\Users\xyz\projects\swc-win32\node_modules\.bin\swc
C:\Users\xyz\projects\swc-win32\node_modules\@node-rs\helper\lib\loader.js:27
    throw new TypeError(errorMsg);
    ^

TypeError: Can not find node binding files from @swc/core-win32-x64-gnu, @swc/core-win32-x64-msvc and C:\Users\xyz\projects\swc-win32\node_modules\@swc\core\swc.win32-x64-gnu.node, C:\Users\xyz\projects\swc-win32\node_modules\@swc\core\swc.win32-x64-msvc.node
    at Object.loadBinding (C:\Users\xyz\projects\swc-win32\node_modules\@node-rs\helper\lib\loader.js:27:11)
    at Object.<anonymous> (C:\Users\xyz\projects\swc-win32\node_modules\@swc\core\index.js:26:27)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Object.<anonymous> (C:\Users\xyz\projects\swc-win32\node_modules\@swc\cli\lib\src\swc\util.js:35:26)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
error Command failed with exit code 1.

In fact this is copied from my minimal recreation of the same problem inside my Windows 10 VM.
But through swc-loader the error was the same.

The files C:\Users\xyz\projects\swc-win32\node_modules\@swc\core\swc.win32-x64-gnu.node and C:\Users\xyz\projects\swc-win32\node_modules\@swc\core\swc.win32-x64-msvc.node do not exist.
But the package @swc/core-win32-x64-msvc seems to have been installed:

 ls C:\Users\xyz\projects\swc-win32\node_modules\@swc\     


    Directory: C:\Users\xyz\projects\swc-win32\node_modules\@swc


Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
d-----         1/22/2021   3:19 PM                cli
d-----         1/22/2021   3:19 PM                core
d-----         1/22/2021   3:19 PM                core-win32-x64-msvc

Input code
My minimal example only contains this package.json:

{
  "devDependencies": {
    "@swc/cli": "^0.1.32",
    "@swc/core": "^1.2.45"
  }
}

Config
// since this is a minimal example, i don't have a .swcrc

Expected behavior
swc cli to work

Version
The version of @swc/core: 1.2.45

Additional context
yarn versions says:

yarn versions v1.22.5
{
  yarn: '1.22.5',
  node: '14.15.4',
  v8: '8.4.371.19-node.17',
  uv: '1.40.0',
  zlib: '1.2.11',
  brotli: '1.0.9',
  ares: '1.16.1',
  modules: '83',
  nghttp2: '1.41.0',
  napi: '7',
  llhttp: '2.1.3',
  openssl: '1.1.1i',
  cldr: '37.0',
  icu: '67.1',
  tz: '2020a',
  unicode: '13.0'
}

I would appreciate any help :)

@kdy1
Copy link
Member

kdy1 commented Jan 22, 2021

Did you run npm install after copying?

cc @Brooooooklyn

@tw-360vier
Copy link
Author

tw-360vier commented Jan 22, 2021

Oh i did not copy the project.
I created this minimal project on the windows machine:

yarn init
yarn add -D @swc/core @swc/cli

@Brooooooklyn
Copy link
Member

@tw-360vier I could not reproduce on my windows virtual machine, does swc.win32-x64-msvc.node existed in node_modules/@swc/core-win32-x64-msvc folder ?

@tw-360vier
Copy link
Author

@Brooooooklyn yes it's there:

 ls .\node_modules\@swc\core-win32-x64-msvc\


    Directory: C:\Users\xyz\projects\swc-win32\node_modules\@swc\core-win32-x64-msvc


Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a----         1/22/2021  12:43 PM            773 package.json
-a----         1/22/2021  12:43 PM             92 README.md
-a----         1/22/2021  12:43 PM       31024128 swc.win32-x64-msvc.node

@Brooooooklyn
Copy link
Member

@tw-360vier delete node_modules and yarn.lock and reinstall, then try again

@tw-360vier
Copy link
Author

@Brooooooklyn same result:

C:\Users\xyz\projects\swc-win32> del .\node_modules\

Confirm
The item at C:\Users\xyz\projects\swc-win32\node_modules\ has children and the Recurse parameter was not specified. If you continue, all children will be removed with the item. Are you sure you want to continue?
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"): Y
PS C:\Users\xyz\projects\swc-win32> del .\yarn.lock
PS C:\Users\xyz\projects\swc-win32> yarn
yarn install v1.22.5
warning package.json: No license field
info No lockfile found.
warning No license field
[1/4] Resolving packages...
[2/4] Fetching packages...
info @swc/core-linux-x64-gnu@1.2.45: The platform "win32" is incompatible with this module.
info "@swc/core-linux-x64-gnu@1.2.45" is an optional dependency and failed compatibility check. Excluding it from installation.
info @swc/core-linux-arm-gnueabihf@1.2.45: The platform "win32" is incompatible with this module.
info "@swc/core-linux-arm-gnueabihf@1.2.45" is an optional dependency and failed compatibility check. Excluding it from installation.
info @swc/core-linux-arm-gnueabihf@1.2.45: The CPU architecture "x64" is incompatible with this module.
info @swc/core-linux-arm64-gnu@1.2.45: The platform "win32" is incompatible with this module.
info "@swc/core-linux-arm64-gnu@1.2.45" is an optional dependency and failed compatibility check. Excluding it from installation.
info @swc/core-linux-arm64-gnu@1.2.45: The CPU architecture "x64" is incompatible with this module.
info @swc/core-darwin-x64@1.2.45: The platform "win32" is incompatible with this module.
info "@swc/core-darwin-x64@1.2.45" is an optional dependency and failed compatibility check. Excluding it from installation.
info @swc/core-darwin-arm64@1.2.45: The platform "win32" is incompatible with this module.
info "@swc/core-darwin-arm64@1.2.45" is an optional dependency and failed compatibility check. Excluding it from installation.
info @swc/core-darwin-arm64@1.2.45: The CPU architecture "x64" is incompatible with this module.
info @swc/core-linux-x64-musl@1.2.45: The platform "win32" is incompatible with this module.
info "@swc/core-linux-x64-musl@1.2.45" is an optional dependency and failed compatibility check. Excluding it from installation.
info @swc/core-android-arm64@1.2.45: The platform "win32" is incompatible with this module.
info "@swc/core-android-arm64@1.2.45" is an optional dependency and failed compatibility check. Excluding it from installation.
info @swc/core-android-arm64@1.2.45: The CPU architecture "x64" is incompatible with this module.
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Saved lockfile.
Done in 4.89s.
PS C:\Users\xyz\projects\swc-win32> yarn swc
yarn run v1.22.5
warning package.json: No license field
$ C:\Users\xyz\projects\swc-win32\node_modules\.bin\swc
C:\Users\xyz\projects\swc-win32\node_modules\@node-rs\helper\lib\loader.js:27
    throw new TypeError(errorMsg);
    ^

TypeError: Can not find node binding files from @swc/core-win32-x64-gnu, @swc/core-win32-x64-msvc and C:\Users\xyz\projects\swc-win32\node_modules\@swc\core\swc.win32-x64-gnu.node, C:\Users\xyz\projects\swc-win32\node_modules\@swc\core\swc.win32-x64-msvc.node
    at Object.loadBinding (C:\Users\xyz\projects\swc-win32\node_modules\@node-rs\helper\lib\loader.js:27:11)
    at Object.<anonymous> (C:\Users\xyz\projects\swc-win32\node_modules\@swc\core\index.js:26:27)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Object.<anonymous> (C:\Users\xyz\projects\swc-win32\node_modules\@swc\cli\lib\src\swc\util.js:35:26)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

@Brooooooklyn
Copy link
Member

I have tried many times from scratch and everything is ok on my windows vm. I'm using yarn@1.22.5 and node@14.15.4.

Could you add some debug log in library source code under the node_modules?

Add console.error(e) in node_modules/@node-rs/helper/lib/loader.js:L17:

for (const triple of triples) {
    if (packageName) {
        try {
            return require(require.resolve(`${packageName}-${triple.platformArchABI}`, { paths: [dirname] }));
        }
        catch (e) { } // ---------------------------------- add here
    }
    const localFilePath = path_1.join(dirname, `${filename}.${triple.platformArchABI}.node`);
    if (fs_1.existsSync(localFilePath)) {
        return require(localFilePath);
    }
}

@tw-360vier
Copy link
Author

@Brooooooklyn
I updated all my chocolatey packages and now i can't reproduce it anymore, either.

@sabberworm
Copy link

sabberworm commented Feb 1, 2021

Two colleagues of mine have the same exact error on their windowses. The binary is there but loading it doesn’t work. Even doing so manually with node results in an error message:

> node.exe -r '@swc/core-win32-x64-msvc/swc.win32-x64-msvc'

internal/modules/cjs/loader.js:1208
  return process.dlopen(module, path.toNamespacedPath(filename));
                 ^

Error: The specified module could not be found.
\\?\C:\REDACTED\node_modules\@swc\core-win32-x64-msvc\swc.win32-x64-msvc.node
    at Object.Module._extensions..node (internal/modules/cjs/loader.js:1208:18)
    at Module.load (internal/modules/cjs/loader.js:1002:32)
    at Function.Module._load (internal/modules/cjs/loader.js:901:14)
    at Module.require (internal/modules/cjs/loader.js:1044:19)
    at Module._preloadModules (internal/modules/cjs/loader.js:1298:12)
    at loadPreloadModules (internal/bootstrap/pre_execution.js:444:5)
    at prepareMainThreadExecution (internal/bootstrap/pre_execution.js:68:3)
    at internal/main/eval_stdin.js:17:1

(This works just fine on my windows install. And three other colleagues’.)

On both my machine and the machine that isn’t working outputs of cygwin file for both node and swc.win32-x64-msvc.node are identical:

swc.win32-x64-msvc.node: PE32+ executable (DLL) (GUI) x86-64, for MS Windows
node.exe: PE32+ executable (console) x86-64, for MS Windows

I thought perhaps it’s an overbearing anti-virus that prevents loading the DLL but only basic windows defender is active.

We all have the same version of node (v12.16.1; in fact, installed locally to the project folder by the build script) and use npm ci to install dependencies from lockfile only. So there shouldn’t be any differing versions in node_modules either.

@Brooooooklyn
Copy link
Member

@sabberworm could you please add debug log in #1351 (comment) and try again?

@sabberworm
Copy link

sabberworm commented Feb 1, 2021

Unfortunately it doesn’t give us any more information, just the same nondescript “The specified module could not be found” as the manual method I posted above.

The specified module could not be found.
\\?\C:\REDACTED\node_modules\@swc\core-win32-x64-msvc\swc.win32-x64-msvc.node
    at Object.Module._extensions..node (internal/modules/cjs/loader.js:1208:18)
    at Module.load (internal/modules/cjs/loader.js:1002:32)
    at Function.Module._load (internal/modules/cjs/loader.js:901:14)
    at Module.require (internal/modules/cjs/loader.js:1044:19)
    at require (C:\REDACTED\node_modules\webpack-cli\node_modules\v8-compile-cache\v8-compile-cache.js:159:20)
    at Object.loadBinding (C:\REDACTED\node_modules\@node-rs\helper\lib\loader.js:15:24)
    at Object.<anonymous> (C:\REDACTED\node_modules\@swc\core\index.js:26:27)
    at Module._compile (C:\REDACTED\node_modules\webpack-cli\node_modules\v8-compile-cache\v8-compile-cache.js:192:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)
    at Module.load (internal/modules/cjs/loader.js:1002:32)
Error: Cannot find module '@swc/core-win32-x64-gnu'
Require stack:
- C:\REDACTED\node_modules\@node-rs\helper\lib\loader.js
- C:\REDACTED\node_modules\@node-rs\helper\lib\index.js
- C:\REDACTED\node_modules\@swc\core\index.js
- C:\REDACTED\node_modules\swc-loader\src\index.js
- C:\REDACTED\node_modules\loader-runner\lib\loadLoader.js
- C:\REDACTED\node_modules\loader-runner\lib\LoaderRunner.js
- C:\REDACTED\node_modules\webpack\lib\NormalModule.js
- C:\REDACTED\node_modules\webpack\lib\LoaderTargetPlugin.js
- C:\REDACTED\node_modules\html-webpack-plugin\lib\child-compiler.js
- C:\REDACTED\node_modules\html-webpack-plugin\lib\cached-child-compiler.js
- C:\REDACTED\node_modules\html-webpack-plugin\index.js
- C:\REDACTED\webpack.config.default.js
- C:\REDACTED\node_modules\webpack-cli\lib\webpack-cli.js
- C:\REDACTED\node_modules\webpack-cli\lib\bootstrap.js
- C:\REDACTED\node_modules\webpack-cli\bin\cli.js
- C:\REDACTED\node_modules\webpack\bin\webpack.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:982:15)
    at Function.resolve (C:\REDACTED\node_modules\webpack-cli\node_modules\v8-compile-cache\v8-compile-cache.js:164:23)
    at Object.loadBinding (C:\REDACTED\node_modules\@node-rs\helper\lib\loader.js:15:40)
    at Object.<anonymous> (C:\REDACTED\node_modules\@swc\core\index.js:26:27)
    at Module._compile (C:\REDACTED\node_modules\webpack-cli\node_modules\v8-compile-cache\v8-compile-cache.js:192:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)
    at Module.load (internal/modules/cjs/loader.js:1002:32)
    at Function.Module._load (internal/modules/cjs/loader.js:901:14)
    at Module.require (internal/modules/cjs/loader.js:1044:19)
    at require (C:\REDACTED\node_modules\webpack-cli\node_modules\v8-compile-cache\v8-compile-cache.js:159:20) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    'C:\\REDACTED\\node_modules\\@node-rs\\helper\\lib\\loader.js',
    'C:\\REDACTED\\node_modules\\@node-rs\\helper\\lib\\index.js',
    'C:\\REDACTED\\node_modules\\@swc\\core\\index.js',
    'C:\\REDACTED\\node_modules\\swc-loader\\src\\index.js',
    'C:\\REDACTED\\node_modules\\loader-runner\\lib\\loadLoader.js',
    'C:\\REDACTED\\node_modules\\loader-runner\\lib\\LoaderRunner.js',
    'C:\\REDACTED\\node_modules\\webpack\\lib\\NormalModule.js',
    'C:\\REDACTED\\node_modules\\webpack\\lib\\LoaderTargetPlugin.js',
    'C:\\REDACTED\\node_modules\\html-webpack-plugin\\lib\\child-compiler.js',
    'C:\\REDACTED\\node_modules\\html-webpack-plugin\\lib\\cached-child-compiler.js',
    'C:\\REDACTED\\node_modules\\html-webpack-plugin\\index.js',
    'C:\\REDACTED\\webpack.config.default.js',
    'C:\\REDACTED\\node_modules\\webpack-cli\\lib\\webpack-cli.js',
    'C:\\REDACTED\\node_modules\\webpack-cli\\lib\\bootstrap.js',
    'C:\\REDACTED\\node_modules\\webpack-cli\\bin\\cli.js',
    'C:\\REDACTED\\node_modules\\webpack\\bin\\webpack.js'
  ]
}

@mewhhaha
Copy link

mewhhaha commented Mar 2, 2021

I was helping a coworker (also using Windows) with this issue recently, and he was using the following tools in our monorepo

node 14.15.4
npm 7.5.5
pnpm 5.18.1

We resolved it by downgrading npm to the version shipping with node 14 (6.14.11). Maybe some of these problems are caused by this?

@Brooooooklyn
Copy link
Member

I will check the npm@7 tomorrow

@mewhhaha
Copy link

mewhhaha commented Mar 2, 2021

I didn't look further into it, but I have other coworkers using the node 15 + npm 7 with swc so I think it's a mismatch issue if anything.

@yaxiaoliu
Copy link

$ uname -srm
Linux 4.9.151-015.ali3000.alios7.x86_64 x86_64

image

node: 12.21.0
npm: 6.14.11
@swc/core: 1.2.52

@Brooooooklyn

@Brooooooklyn
Copy link
Member

Open napi-rs/node-rs#427 to track this problem

@rasmusrim
Copy link

I know this is a bit old, but I had a similar issue yesterday and just wanted to help anyone stumbling upon this thread because of a similar search.

I solved this problem by installing the Visual C++ redistributables: https://learn.microsoft.com/en-us/cpp/windows/latest-supported-vc-redist?view=msvc-170

@mmeah-riverstar
Copy link

I know this is a bit old, but I had a similar issue yesterday and just wanted to help anyone stumbling upon this thread because of a similar search.

I solved this problem by installing the Visual C++ redistributables: https://learn.microsoft.com/en-us/cpp/windows/latest-supported-vc-redist?view=msvc-170

Thank you!

@swc-bot
Copy link
Collaborator

swc-bot commented Dec 1, 2022

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@swc-project swc-project locked as resolved and limited conversation to collaborators Dec 1, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

Successfully merging a pull request may close this issue.

9 participants