Skip to content

[Bug]: "npx rspack preview" not working after version 1.2.3 #9460

@kno-raziel

Description

@kno-raziel

System Info

System:
OS: macOS 15.3.1
CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
Memory: 39.12 MB / 16.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 20.18.3 - ~/.nvm/versions/node/v20.18.3/bin/node
Yarn: 1.22.22 - ~/.nvm/versions/node/v20.18.3/bin/yarn
npm: 10.8.2 - ~/.nvm/versions/node/v20.18.3/bin/npm
Browsers:
Chrome: 133.0.6943.127
Edge: 133.0.3065.82
Safari: 18.3
npmPackages:
@rspack/cli: 1.2.4 => 1.2.4
@rspack/core: 1.2.4 => 1.2.4
@rspack/plugin-react-refresh: ^1.0.1 => 1.0.1

Details

I started to get the following error this week when running npx rspack preview --port 2900

/Users/HIDDEN_PATH/rspack.config.ts:1
import { defineConfig } from "@rspack/cli";
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at wrapSafe (node:internal/modules/cjs/loader:1378:20)
    at Module._compile (node:internal/modules/cjs/loader:1428:41)
    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 crossImport (/Users/HIDDEN_PATH/node_modules/@rspack/cli/dist/index.js:515:22)
    at loadRspackConfig (/Users/HIDDEN_PATH/node_modules/@rspack/cli/dist/index.js:563:20)
    at RspackCLI.loadConfig (/Users/HIDDEN_PATH/node_modules/@rspack/cli/dist/index.js:694:38)

in the project I'm working we have this versions in the package.json:

"@rspack/cli": "^1.2.3",
"@rspack/core": "^1.2.3",
"@rspack/plugin-react-refresh": "^1.0.1",

I have tried with a fresh project using yarn create rspack that have installed the following versions in the package.json:

"@rspack/cli": "^1.2.6",
"@rspack/core": "^1.2.6",
"@rspack/plugin-react-refresh": "^1.0.1", 

And got same error

I have tried pinning versions to the following in the package.json:

"@rspack/cli": "1.2.3",
"@rspack/core": "1.2.3",

and it successfully work

Image

I have tried pinning versions to the following in the package.json:

"@rspack/cli": "1.2.4",
"@rspack/core": "1.2.4",

and it failed, so that makes me think a bug was introduced in v1.24 🤔

Image

Reproduce link

No response

Reproduce Steps

Steps:

  1. create new rspack project : yarn create rspack
  2. install modules: yarn install
  3. build that project: yarn run build
  4. try to preview build: npx rspack preview --port 2900
  5. 😵

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions