Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

import失败,提示export 'default' (imported as 'impl') was not found in '../proto/proto.min' #4

Closed
imndx opened this issue Jul 8, 2021 · 1 comment

Comments

@imndx
Copy link
Contributor

imndx commented Jul 8, 2021

原因是proto.min.jsbase64.min.js不需要通过babel转换,需要在babel的配置文件中将这两个文件忽略。

.babelrc参考配置如下:

{
 "presets": [
   ["env", {
     "modules": false,
     "targets": {
       "browsers": ["> 1%", "last 2 versions", "not ie <= 8"]
     }
   }],
   "stage-2"
 ],
 "plugins": ["transform-vue-jsx", "transform-runtime"],
 "ignore": [
   "**/base64.min.js",
   "**/proto.min.js",
   "**/engine.min.js"
 ]
}

@imndx imndx changed the title export 'default' (imported as 'impl') was not found in '../proto/proto.min' import失败,提示export 'default' (imported as 'impl') was not found in '../proto/proto.min' Jul 8, 2021
@imndx imndx pinned this issue Jul 8, 2021
@imndx imndx closed this as completed Jul 8, 2021
@imndx
Copy link
Contributor Author

imndx commented Nov 26, 2022

如果是create-react-app创建的react应用的话,默认没有开放配置,可以这么:

  1. 执行yarn eject或者npm run eject会在项目目录下生成config目录,该目录包含默认配置
  2. 修改config/webpack.config.js,在babel相关配置部分,加上上面的ignore配置,如下:

            // Process application JS with Babel.
            // The preset includes JSX, Flow, TypeScript, and some ESnext features.
            {
              test: /\.(js|mjs|jsx|ts|tsx)$/,
              include: paths.appSrc,
              loader: require.resolve('babel-loader'),
              options: {
                customize: require.resolve(
                  'babel-preset-react-app/webpack-overrides'
                ),
                presets: [
                  [
                    require.resolve('babel-preset-react-app'),
                    {
                      runtime: hasJsxRuntime ? 'automatic' : 'classic',
                    },
                  ],
                ],
                
                plugins: [
                  isEnvDevelopment &&
                    shouldUseReactRefresh &&
                    require.resolve('react-refresh/babel'),
                ].filter(Boolean),

                 // 下面 ignore 配置是新添加
                // ================================================================================
                 ignore: [
                   "**/base64.min.js",
                   "**/proto.min.js",
                   "**/engine.min.js"
                 ],
                // 上面 ignore 配置是新添加的
                // ===============================================================================

                // This is a feature of `babel-loader` for webpack (not Babel itself).
                // It enables caching results in ./node_modules/.cache/babel-loader/
                // directory for faster rebuilds.
                cacheDirectory: true,
                // See #6846 for context on why cacheCompression is disabled
                cacheCompression: false,
                compact: isEnvProduction,
              },
            },

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant