简体   繁体   English

react-app-rewired 构建抛出尝试导入错误

[英]react-app-rewired build throws attempted import error

I have a monorepo with react-native for mobile and react for web.我有一个带有 react-native 的 monorepo 用于移动设备,并对 web 做出反应。 When I use "react-app-rewired build", I get the following error:当我使用“react-app-rewired build”时,我收到以下错误:

node_modules/@react-navigation/core/lib/module/getStateFromPath.js
Attempted import error: 'parse' is not exported from 'query-string' (imported as 'queryString').

So clearly something is messed up with the import/exports, but "start" works correctly, and everything's fine with that.很明显,导入/导出有些东西搞砸了,但是“开始”工作正常,一切都很好。 This only occurs on "build".这只发生在“构建”上。 I use "customize-cra" to get rid of the ModuleScopePlugin so I can import outside of src我使用“customize-cra”来摆脱 ModuleScopePlugin,这样我就可以在 src 之外导入

const { removeModuleScopePlugin, override, babelInclude, addBabelPlugins } = require("customize-cra");
const path = require("path");

module.exports = override(
  removeModuleScopePlugin(),        // (1)
  babelInclude([
    path.resolve("src"),
    path.resolve("../components/src"),  // (2)
    path.resolve('../../node_modules'),
  ]),
  addBabelPlugins([require.resolve('babel-plugin-react-native-web')])
);

This is my config-overrides.js.这是我的 config-overrides.js。 My tsconfig was not changed, it's the same that ships with cra.我的 tsconfig 没有改变,它与 cra 附带的相同。 If any additional information is needed, I'll add that.如果需要任何其他信息,我会添加。 Thanks!谢谢!

I had the same issue when using react-app-rewired.使用 react-app-rewired 时我遇到了同样的问题。

You can try using craco to override your webpack config instead.您可以尝试使用 craco 覆盖您的 webpack 配置。 Switching to craco somehow eliminates this error for me.切换到 craco 以某种方式为我消除了这个错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM