解决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.

// 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:

...
"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:

"scripts": {
    "start": "cross-env GENERATE_SOURCEMAP=false react-scripts start"
}
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
若使用 v5 版本的 react-router-dom 出现不到 useHistory 的错误,可能有以下几个原因。 首先,你需要确认你已经正确地安装了 react-router-dom,并且确保你已经更新到了 v5 版本。你可以使用 `npm list react-router-dom` 命令检查版本号,如果没有正确安装或者版本不正确,你可以使用 `npm install react-router-dom@v5` 命令重新安装。 其次,你需要在代码中正确导入 useHistory。你可以使用以下代码导入 useHistory: ``` import { useHistory } from 'react-router-dom'; ``` 然后,你需要在函数组件中使用 useHistory。useHistory 是一个自定义的 React Hook,用于在函数组件中获取 history 对象。确保你在函数组件的作用域中正确使用它,例如: ``` const YourComponent = () => { const history = useHistory(); // 在这里可以使用 history 对象进行路由导航等操作 ... return ( ... ) } ``` 最后,如果以上方法都尝试过后仍然无法解决问题,可能是其他地方出现了错误导致无法到 useHistory。你可以检查你的代码中是否存在拼写错误或者其他语法错误,也可以考虑重新启动开发服务器或者清除缓存来刷新代码。 总的来说,如果你正确安装了 v5 版本的 react-router-dom,并正确导入和使用 useHistory,就不应该出现不到 useHistory 的错误。你可以再仔细检查一下以上的步骤,或者提供更多的错误信息以便我们更好地帮助你解决问题。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值