解决react启动服务时source-map-loader插件报错找不到源文件“index.ts“的源映射文件

webpack 5: Failed to parse source map from “**********” 如下图所示:
在这里插入图片描述
The source map files links to the src/ - folder that is not distributed.

// node_modules/@mswjs/interceptors/lib/interceptors/utils/uuid.js.map
{
   "version":3,"file":"uuid.js","sourceRoot":"","sources":["../../-->src<--/utils/uuid.ts"] ...}

In the source-map-loader README it says: “The source-map-loader will extract from any JavaScript file, including those in the node_modules directory.”.
As for CRA 5: I think a change was added in this PR: facebook/create-react-app#8227 Commit: facebook/create-react-app@382ba21#diff-8e25c4f6f592c1fcfc38f0d43d62cbd68399f44f494c1b60f0cf9ccd7344d697 Current source: https://github.com/facebook/create-react-app/blob/9673858a3715287c40aef9e800c431c7d45c05a2/packages/react-scripts/config/webpack.config.js#L350
I’m seeing these warnings when starting the dev server using react-scripts start, If i exclude the above config by setting GENERATE_SOURCEMAP=false when starting the dev server the warnings disappear.

In case someone is lost on how to do it, just add the GENERATE_SOURCEMAP=false before the start script. In my case:

...
"scripts": {
   
    "start": "GENERATE_SOURCEMAP=false react-scripts start",
   ...
  },

For Windows Users 🚀
1.Create an environment variables file named .env in the project root and add GENERATE_SOURCEMAP=false to it.

OR

2.Run npm i -D cross-env and then in the package.json file update the start script to the following:

"scripts": {
   
    "start": "cross-env GENERATE_SOURCEMAP=false react-scripts start"
}

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2023-12-11 13:08:03       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2023-12-11 13:08:03       100 阅读
  3. 在Django里面运行非项目文件

    2023-12-11 13:08:03       82 阅读
  4. Python语言-面向对象

    2023-12-11 13:08:03       91 阅读

热门阅读

  1. 【华为OD机试python】分苹果【2023 B卷|100分】

    2023-12-11 13:08:03       66 阅读
  2. 选项式API和组合式API

    2023-12-11 13:08:03       56 阅读
  3. Git常用命令

    2023-12-11 13:08:03       54 阅读
  4. [git] 远程删除分支

    2023-12-11 13:08:03       57 阅读
  5. Vue中路由的使用

    2023-12-11 13:08:03       62 阅读
  6. windows常见快捷键

    2023-12-11 13:08:03       63 阅读
  7. vue3页面调接口时加载卡住不响应

    2023-12-11 13:08:03       50 阅读
  8. php 导入excel

    2023-12-11 13:08:03       52 阅读
  9. linux shell

    2023-12-11 13:08:03       42 阅读
  10. GORM 自定义数据类型json-切片(数组)

    2023-12-11 13:08:03       76 阅读