解决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"
}
相关推荐
半个落月3 分钟前
React 性能优化入门:用 memo 避免无关的子组件重复渲染
前端·react.js
北城笑笑11 分钟前
Server 18 ,Nginx + Vite 前端部署排错实战:从 `/api/gpt/chat` 404 到 9012 后端服务的完整定位过程
linux·运维·前端·nginx·ubuntu·vue
江华森14 分钟前
从抓包到嗅探:用 C 语言把《计算机网络》第 9-13 章全部跑一遍
前端
IT_陈寒32 分钟前
Vite打包给我挖的这个坑,差点搞崩我的项目
前端·人工智能·后端
恋猫de小郭1 小时前
Flutter A2UI 的正确用法,怎么把 AI 和动态 UI 结合有效生产
android·前端·flutter
程序员-珍1 小时前
安卓开发:同名 styles.xml 在不同分支/文件夹的合并规则
android·xml·前端
Ashley的成长之路1 小时前
前端性能优化实战手册·第5篇(最终篇):性能监控与 CI/CD 集成
前端·ci/cd·性能优化
chemddd1 小时前
第四节课:前端
前端
雪芽蓝域zzs1 小时前
(一)Vue3+JS+Vite+pnpm 仿若依后台 从零搭建
前端
常宇佳2 小时前
vue3 $refs使用方法
前端·vue.js·typescript