Unverified Commit 1a10ab8c authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Update error for failing to load SWC bindings (#30269)

parent 085df63b
...@@ -95,7 +95,7 @@ jobs: ...@@ -95,7 +95,7 @@ jobs:
runs-on: windows-latest runs-on: windows-latest
env: env:
CARGO_PROFILE_RELEASE_CODEGEN_UNITS: 32 CARGO_PROFILE_RELEASE_CODEGEN_UNITS: 32
CARGO_PROFILE_RELEASE_LTO: "false" CARGO_PROFILE_RELEASE_LTO: 'false'
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
...@@ -160,7 +160,6 @@ jobs: ...@@ -160,7 +160,6 @@ jobs:
name: next-swc-binaries name: next-swc-binaries
path: packages/next/native/next-swc.*.node path: packages/next/native/next-swc.*.node
build-linux-musl: build-linux-musl:
name: next-swc - linux-musl - node@lts name: next-swc - linux-musl - node@lts
runs-on: ubuntu-latest runs-on: ubuntu-latest
...@@ -187,7 +186,7 @@ jobs: ...@@ -187,7 +186,7 @@ jobs:
docker pull ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-alpine docker pull ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-alpine
docker tag ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-alpine builder docker tag ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-alpine builder
- name: "Build" - name: 'Build'
run: | run: |
docker run --rm -v $(pwd)/packages/next:/swc -w /swc builder sh -c "yarn build-native" docker run --rm -v $(pwd)/packages/next:/swc -w /swc builder sh -c "yarn build-native"
...@@ -197,7 +196,6 @@ jobs: ...@@ -197,7 +196,6 @@ jobs:
name: next-swc-binaries name: next-swc-binaries
path: packages/next/native/next-swc.*.node path: packages/next/native/next-swc.*.node
build-linux-aarch64: build-linux-aarch64:
name: next-swc - aarch64-unknown-linux-gnu - node@14 name: next-swc - aarch64-unknown-linux-gnu - node@14
runs-on: ubuntu-18.04 runs-on: ubuntu-18.04
...@@ -241,7 +239,6 @@ jobs: ...@@ -241,7 +239,6 @@ jobs:
name: next-swc-binaries name: next-swc-binaries
path: packages/next/native/next-swc.*.node path: packages/next/native/next-swc.*.node
build-linux-aarch64-musl: build-linux-aarch64-musl:
name: next-swc - aarch64-unknown-linux-musl - node@14 name: next-swc - aarch64-unknown-linux-musl - node@14
runs-on: ubuntu-18.04 runs-on: ubuntu-18.04
...@@ -283,7 +280,6 @@ jobs: ...@@ -283,7 +280,6 @@ jobs:
name: next-swc-binaries name: next-swc-binaries
path: packages/next/native/next-swc.*.node path: packages/next/native/next-swc.*.node
build-linux-arm7: build-linux-arm7:
name: next-swc - arm7-unknown-linux-gnu - node@14 name: next-swc - arm7-unknown-linux-gnu - node@14
runs-on: ubuntu-18.04 runs-on: ubuntu-18.04
...@@ -368,12 +364,12 @@ jobs: ...@@ -368,12 +364,12 @@ jobs:
id: build id: build
uses: vmactions/freebsd-vm@v0.1.5 uses: vmactions/freebsd-vm@v0.1.5
env: env:
DEBUG: "napi:*" DEBUG: 'napi:*'
RUSTUP_HOME: /usr/local/rustup RUSTUP_HOME: /usr/local/rustup
CARGO_HOME: /usr/local/cargo CARGO_HOME: /usr/local/cargo
RUSTUP_IO_THREADS: 1 RUSTUP_IO_THREADS: 1
with: with:
envs: "DEBUG RUSTUP_HOME CARGO_HOME RUSTUP_IO_THREADS" envs: 'DEBUG RUSTUP_HOME CARGO_HOME RUSTUP_IO_THREADS'
usesh: true usesh: true
mem: 6000 mem: 6000
prepare: | prepare: |
...@@ -402,7 +398,7 @@ jobs: ...@@ -402,7 +398,7 @@ jobs:
rm -rf target rm -rf target
working-directory: packages/next working-directory: packages/next
- name: "List files" - name: 'List files'
run: ls -la run: ls -la
- name: Upload artifact - name: Upload artifact
...@@ -411,7 +407,6 @@ jobs: ...@@ -411,7 +407,6 @@ jobs:
name: next-swc-binaries name: next-swc-binaries
path: packages/next/native/next-swc.*.node path: packages/next/native/next-swc.*.node
commit: commit:
needs: needs:
- build-native - build-native
......
# SWC Failed to Load
#### Why This Message Occurred
Next.js now uses Rust-based compiler [SWC](https://swc.rs/) to compile JavaScript/TypeScript. This new compiler is up to 17x faster than Babel when compiling individual files and up to 5x faster Fast Refresh.
SWC requires a binary be downloaded that is compatible specific to your system. In some cases this binary may fail to load either from failing to download or an incompatibility with your architecture.
#### Possible Ways to Fix It
If SWC continues to fail to load you can opt-out by disabling `swcMinify` in your `next.config.js` or by adding a `.babelrc` to your project with the following content:
```json
{
"presets": ["next/babel"]
}
```
Be sure to report the issue on [the feedback thread](https://github.com/vercel/next.js/discussions/30174) sharing the below information so we can get it fixed:
- your node architecture and platform `node -e 'console.log(process.arch, process.platform)'`
- your operating system version and CPU
- your Next.js version `yarn next --version`
- your package manager (`yarn` or `npm`) and version
- your node.js version `node -v`
- whether `@next/swc-<your-system-version>` was downloaded in `node_modules` correctly
### Useful Links
- [SWC Feedback Thread](https://github.com/vercel/next.js/discussions/30174)
- [SWC Disabled Document](https://nextjs.org/docs/messages/swc-disabled)
...@@ -8,6 +8,10 @@ ...@@ -8,6 +8,10 @@
"title": "beta-middleware", "title": "beta-middleware",
"path": "/errors/beta-middleware.md" "path": "/errors/beta-middleware.md"
}, },
{
"title": "failed-loading-swc",
"path": "/errors/failed-loading-swc.md"
},
{ {
"title": "deprecated-target-config", "title": "deprecated-target-config",
"path": "/errors/deprecated-target-config.md" "path": "/errors/deprecated-target-config.md"
......
const { loadBinding } = require('@node-rs/helper') const { loadBinding } = require('@node-rs/helper')
const path = require('path') const path = require('path')
const Log = require('../output/log')
/** /**
* __dirname means load native addon from current dir * __dirname means load native addon from current dir
...@@ -9,11 +10,24 @@ const path = require('path') ...@@ -9,11 +10,24 @@ const path = require('path')
* `loadBinding` helper will load `next-swc.[PLATFORM].node` from `__dirname` first * `loadBinding` helper will load `next-swc.[PLATFORM].node` from `__dirname` first
* If failed to load addon, it will fallback to load from `next-swc-[PLATFORM]` * If failed to load addon, it will fallback to load from `next-swc-[PLATFORM]`
*/ */
const bindings = loadBinding( let bindings
try {
bindings = loadBinding(
path.join(__dirname, '../../../native'), path.join(__dirname, '../../../native'),
'next-swc', 'next-swc',
'@next/swc' '@next/swc'
) )
} catch (err) {
// only log the original error message as the stack is not
// helpful to the user
console.error(err.message)
Log.error(
`failed to load SWC binary, see more info here: https://nextjs.org/docs/messages/failed-loading-swc`
)
process.exit(1)
}
async function transform(src, options) { async function transform(src, options) {
const isModule = typeof src !== 'string' const isModule = typeof src !== 'string'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment