解决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"
}
相关推荐
cyforkk11 分钟前
Hexo 双分支部署指南:从原理到 Netlify 实战
前端
小小愿望15 分钟前
前端读取与导出XLSX文件实战指南(React+Ant Design)
前端
小小愿望25 分钟前
JavaScript生成随机数的全面指南:别再只会用Math.random()了!
前端
用户8471810541930 分钟前
wps加载项ribbon.js 与 ribbon.xml 的交互
前端
Jackson__31 分钟前
RAG究竟是什么?一文搞懂大模型的记忆增强术
前端
雲墨款哥33 分钟前
JS算法练习-Day10-判断单调数列
前端·javascript·算法
前端市界34 分钟前
前端视角: PyQt6+Vue3 跨界开发实战
前端·qt·pyqt
阅文作家助手开发团队_山神35 分钟前
第四章:Flutter自定义Engine本地依赖与打包流程
前端·flutter
JuneXcy38 分钟前
11.web api 2
前端·javascript·html
zYear44 分钟前
Elpis 全栈应用框架-- 总结
前端·javascript