解决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"
}
相关推荐
庸俗今天不摸鱼7 分钟前
【万字总结】前端全方位性能优化指南(十)——自适应优化系统、遗传算法调参、Service Worker智能降级方案
前端·性能优化·webassembly
黄毛火烧雪下14 分钟前
React Context API 用于在组件树中共享全局状态
前端·javascript·react.js
Apifox24 分钟前
如何在 Apifox 中通过 CLI 运行包含云端数据库连接配置的测试场景
前端·后端·程序员
一张假钞27 分钟前
Firefox默认在新标签页打开收藏栏链接
前端·firefox
高达可以过山车不行27 分钟前
Firefox账号同步书签不一致(火狐浏览器书签同步不一致)
前端·firefox
m0_5937581028 分钟前
firefox 136.0.4版本离线安装MarkDown插件
前端·firefox
掘金一周31 分钟前
金石焕新程 >> 瓜分万元现金大奖征文活动即将回归 | 掘金一周 4.3
前端·人工智能·后端
三翼鸟数字化技术团队1 小时前
Vue自定义指令最佳实践教程
前端·vue.js
Jasmin Tin Wei1 小时前
蓝桥杯 web 学海无涯(axios、ecahrts)版本二
前端·蓝桥杯
圈圈编码1 小时前
Spring Task 定时任务
java·前端·spring