当 运行ning `npm 运行 develop` 时出现错误 #98123 WEBPACK

ERROR #98123 WEBPACK when running `npm run develop`

我想使用 https://www.gatsbyjs.com/docs/quick-start 上的说明创建一个新的 Gatsby 站点,所以我 运行:

npm init gatsby  # see note below
cd my-gatsby-site
npm run develop

注意:我没有更改任何配置,所以我使用 JavaScript(而不是 TypeScript),没有使用 CMS,没有使用样式系统,也没有安装任何附加功能。

在 运行 npm run develop 期间,我收到以下错误:

> my-gatsby-site@1.0.0 develop
> gatsby develop

success compile gatsby files - 0.812s
success load gatsby config - 0.020s
success load plugins - 0.198s
success onPreInit - 0.001s
success initialize cache - 0.121s
success copy gatsby files - 0.113s
success Compiling Gatsby Functions - 0.277s
success onPreBootstrap - 0.294s
success createSchemaCustomization - 0.001s
success Checking for changed pages - 0.001s
success source and transform nodes - 0.065s
success building schema - 0.143s
success createPages - 0.008s
success createPagesStatefully - 0.044s
info Total nodes: 24, SitePage nodes: 4 (use --verbose for breakdown)
success Checking for changed pages - 0.001s
success write out redirect data - 0.041s
success onPostBootstrap - 0.002s
info bootstrap finished - 5.190s
success onPreExtractQueries - 0.002s
success extract queries from components - 0.082s
success write out requires - 0.005s
success run page queries - 0.017s - 3/3 174.40/s

 ERROR #98123  WEBPACK

Generating development JavaScript bundle failed

You must provide the URL of lib/mappings.wasm by calling SourceMapConsumer.initialize({
'lib/mappings.wasm': ... }) before using SourceMapConsumer

File: .cache/app.js


 ERROR #98123  WEBPACK

Generating development JavaScript bundle failed

You must provide the URL of lib/mappings.wasm by calling SourceMapConsumer.initialize({
'lib/mappings.wasm': ... }) before using SourceMapConsumer

File: .cache/polyfill-entry.js

failed Building development bundle - 8.585s
ERROR in ./.cache/app.js
Module build failed (from 
./node_modules/@pmmmwh/react-refresh-webpack-plugin/loader/index.js):
Error: You must provide the URL of lib/mappings.wasm by calling 
SourceMapConsumer.initialize({ 'lib/mappings.wasm': ... }) before using SourceMapConsumer
    at readWasm
(/Users/xfq/test/gatsby-test/my-gatsby-site/node_modules/source-map/lib/read-wasm.js:8:13)
    at wasm
(/Users/xfq/test/gatsby-test/my-gatsby-site/node_modules/source-map/lib/wasm.js:25:16)
    at /Users/xfq/test/gatsby-test/my-gatsby-site/node_modules/source-map/lib/source-map-co
nsumer.js:264:14
    at Object._loader (/Users/xfq/test/gatsby-test/my-gatsby-site/node_modules/@pmmmwh/reac
t-refresh-webpack-plugin/loader/index.js:81:9)

ERROR in ./.cache/polyfill-entry.js
Module build failed (from 
./node_modules/@pmmmwh/react-refresh-webpack-plugin/loader/index.js):
Error: You must provide the URL of lib/mappings.wasm by calling 
SourceMapConsumer.initialize({ 'lib/mappings.wasm': ... }) before using SourceMapConsumer
    at readWasm
(/Users/xfq/test/gatsby-test/my-gatsby-site/node_modules/source-map/lib/read-wasm.js:8:13)
    at wasm
(/Users/xfq/test/gatsby-test/my-gatsby-site/node_modules/source-map/lib/wasm.js:25:16)
    at /Users/xfq/test/gatsby-test/my-gatsby-site/node_modules/source-map/lib/source-map-co
nsumer.js:264:14
    at Object._loader (/Users/xfq/test/gatsby-test/my-gatsby-site/node_modules/@pmmmwh/reac
t-refresh-webpack-plugin/loader/index.js:81:9)

develop compiled with 2 errors
success Writing page-data.json files to public directory - 0.099s - 3/4 40.45/s

环境:

node 18.3.0
npm 8.11.0
OS: macOS 12.4

我不确定如何调试这个问题。谁能指出我正确的方向?

此问题与您的 Node 版本 (^18.0) 有关。

如果您降级到 16,删除您的 node_modules、您的 package-lock.json 并重新安装它们,问题应该会得到解决。

如果这不是一个选项,如果您需要坚持使用版本 18,请在 package.json 中使用以下解决方案:

  "resolutions": {
    "source-map": "^0.8.0-beta.0"
  },

另一个解决方案是通过以下方式将 Gatsby 升级到最新版本:

npm install gatsby@next

可以在以下位置找到更多详细信息:https://github.com/gatsbyjs/gatsby/issues/35607