解决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 分钟前
Flex布局-彻底掌握 flex-grow / flex-shrink / flex-basis
前端·css·css3
DsirNg5 分钟前
上一个封装hooks涉及的知识学习路线
前端·javascript·typescript
遇到困难睡大觉哈哈6 分钟前
Harmony os ArkTS 卡片生命周期管理:我怎么把 EntryFormAbility 用顺手的
前端·harmonyos·鸿蒙
凌览8 分钟前
女朋友换头像比翻书快?我3天肝出一个去水印小程序
前端·后端·面试
IT_陈寒9 分钟前
3个90%开发者都误解的JavaScript原型陷阱:从proto到class的深度剖析
前端·人工智能·后端
9***446312 分钟前
Spring 核心技术解析【纯干货版】- Ⅶ:Spring 切面编程模块 Spring-Instrument 模块精讲
前端·数据库·spring
tsumikistep14 分钟前
【前端】md5 加密算法
前端
拾忆,想起15 分钟前
Dubbo服务调用失败调试指南:从问题定位到快速修复
前端·微服务·架构·dubbo·safari
Json____17 分钟前
uni-app-数码购物商城h5手机端-前端静态网页
前端·uni-app·商城
k***858418 分钟前
删除文件夹,被提示“需要来自 TrustedInstaller 的权限。。。”的解决方案
android·前端·后端