解决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"
}
相关推荐
志尊宝30 分钟前
Vue3 零基础每日笔记(047):动态路由与路由参数——:id 传参、query 传参、props 解耦
前端·javascript·vue.js·笔记·html5
黑马程序员毕设1 小时前
基于微信小程序的二手交易平台设计与实现报告
前端·人工智能·spring boot·后端·考研
cAuth1 小时前
实现一个图形编辑器
前端·架构·计算机图形学
Nayana2 小时前
《Web 到 HarmonyOS》-- 嵌入 Web 与桥接基础
前端
一拳不是超人2 小时前
之前用 AI 两小时写的塔罗网站,我真把它做上线了,然后呢?
前端·人工智能·程序员
flash俊杰3 小时前
ASR 转写与字幕时间轴:强制对齐、CPS 约束与 SRT 工程化
前端
前端炒粉3 小时前
AI工具面经
前端
唐小码3 小时前
裁员的风刮到了三线荒凉的城市
前端
晚安日记wanna3 小时前
React 为何不做双端 diff?Vue 与 React 更新逻辑的三层差异
前端·react.js·面试