解决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"
}
相关推荐
木斯佳2 分钟前
前端八股文面经大全:腾讯WXG技术架构前端面试(2025-11-19)·面经深度解析
前端·面试·架构
感性的程序员小王13 分钟前
HTTPS页面请求HTTP接口失败?一文讲透Mixed Content
前端·后端
用户6000718191030 分钟前
【翻译】我竟渐渐迷上了生成器的设计巧思
前端
Wect33 分钟前
LeetCode 104. 二叉树的最大深度:解题思路+代码解析
前端·算法·typescript
千寻girling35 分钟前
面试官 : “ 请说一下 JS 的常见的数组 和 字符串方法有哪些 ? ”
前端·javascript·面试
Wect37 分钟前
LeetCode 100. 相同的树:两种解法(递归+迭代)详解
前端·算法·typescript
我是伪码农40 分钟前
Vue 大事件管理系统
前端·javascript·vue.js
henry10101042 分钟前
DeepSeek生成的网页版小游戏 - 冰壶
前端·javascript·css·html5
木斯佳1 小时前
前端八股文面经大全:腾讯云前端实习一面(2025-12-26)·面经深度解析
前端·状态模式·腾讯云
哆啦A梦15881 小时前
Vue3魔法手册 作者 张天禹 012_路由_(二)
前端·vue.js·typescript