解决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.

javascript 复制代码
// 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:

javascript 复制代码
...
"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:

javascript 复制代码
"scripts": {
    "start": "cross-env GENERATE_SOURCEMAP=false react-scripts start"
}
相关推荐
Asthenia041234 分钟前
技术复盘:从一次UAT环境CORS故障看配置冗余的危害与最佳实践
前端
csj5039 分钟前
前端基础之《React(1)—webpack简介》
前端·react
被巨款砸中43 分钟前
前端 20 个零依赖浏览器原生 API 实战清单
前端·javascript·vue.js·web
文韬_武略1 小时前
web vue之状态管理Pinia
前端·javascript·vue.js
mosen8681 小时前
【Vue】Vue Router4x关于router-view,transtion,keepalive嵌套写法报错
前端·javascript·vue.js
蓝婴天使2 小时前
基于 React + Go + PostgreSQL + Redis 的管理系统开发框架
react.js·postgresql·golang
写不来代码的草莓熊2 小时前
vue前端面试题——记录一次面试当中遇到的题(5)
前端
weixin_ab2 小时前
【HTML分离术】
前端·html
文心快码BaiduComate3 小时前
新手该如何选择AI编程工具?文心快码Comate全方位体验
前端·后端·程序员
夫唯不争,故无尤也3 小时前
Tomcat 内嵌启动时找不到 Web 应用的路径
java·前端·tomcat