解决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 小时前
Bun 全景指南:下一代 All-in-One 运行时详解与实战
前端·bun
悠闲蜗牛�2 小时前
零成本自建前端性能监控平台:从数据采集到可视化告警实战
前端
SuperEugene2 小时前
常见设计模式在 JS 里的轻量用法:单例、发布订阅、策略
前端·javascript·设计模式·面试
广州华水科技2 小时前
2026年大坝单北斗GNSS形变监测系统推荐榜单
前端
Mike_jia2 小时前
RootDB:开源免费的Web报表工具,让数据可视化如此简单
前端
LawrenceLan2 小时前
31.Flutter 零基础入门(三十一):Stack 与 Positioned —— 悬浮、角标与覆盖布局
开发语言·前端·flutter·dart
前端 贾公子2 小时前
vue3 组件库的设计和实现原理 (下)
前端·javascript·vue.js
你怎么知道我是队长2 小时前
前端学习---HTML---文本标签
前端·学习·html
竟未曾年少轻狂2 小时前
JavaScript 对象与数组
java·前端·javascript·数组·对象
一次旅行2 小时前
XSS总结
前端·xss