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

使用的npm包中引入了 import 'regenerator-runtime/runtime' 构建时报错 #7765

Closed
soulcm opened this issue Sep 28, 2020 · 6 comments
Closed
Labels
F-react Framework - React T-weapp Target - 编译到微信小程序 V-3 Version - 3.x

Comments

@soulcm
Copy link

soulcm commented Sep 28, 2020

相关平台

微信小程序

小程序基础库: 2.13.0
使用框架: React

复现步骤

npm包使用了babel-runtime,编译出的js中包含 import 'regenerator-runtime/runtime'

期望结果

不报错,编译通过

实际结果

变通出错
Module not found: Can't resolve 'regenerator-runtime/runtime' in 'xxxx'
Parsed request is a module

环境信息

Taro CLI 3.0.11 environment info:
    System:
      OS: macOS 10.15.6
      Shell: 5.7.1 - /bin/zsh
    Binaries:
      Node: 12.14.1 - ~/.nvm/versions/node/v12.14.1/bin/node
      Yarn: 1.22.5 - ~/.yarn/bin/yarn
      npm: 6.14.5 - ~/.nvm/versions/node/v12.14.1/bin/npm
    npmPackages:
      @tarojs/cli: 3.0.11 => 3.0.11 
      @tarojs/components: 3.0.11 => 3.0.11 
      @tarojs/mini-runner: 3.0.11 => 3.0.11 
      @tarojs/react: 3.0.11 => 3.0.11 
      @tarojs/runtime: 3.0.11 => 3.0.11 
      @tarojs/taro: 3.0.11 => 3.0.11 
      @tarojs/webpack-runner: 3.0.11 => 3.0.11 
      babel-preset-taro: 3.0.11 => 3.0.11 
      eslint-config-taro: 3.0.11 => 3.0.11 
      react: 16.12.0 => 16.12.0
@taro-bot2 taro-bot2 bot added F-react Framework - React T-weapp Target - 编译到微信小程序 V-3 Version - 3.x labels Sep 28, 2020
@Chen-jj
Copy link
Contributor

Chen-jj commented Oct 9, 2020

@soulcm 提供一下 demo 咯

@soulcm
Copy link
Author

soulcm commented Oct 13, 2020

babel配置 使用runtime插件以及preset-env, 代码中写上async await函数, 编译出的代码中将包含 import 'regenerator-runtime/runtime';的代码

module.exports = {
  presets: [
    [
      '@babel/preset-env',
      {
        modules: false,
        useBuiltIns: 'usage'
      },
    ]
  ],
  plugins: [
    '@babel/plugin-transform-runtime',
  ],
};

使用taro/cli工具编译小程序,小程序代码中引入此代码库,将会报上面所描述的错误(编译config中使用官方默认配置)

@soulcm
Copy link
Author

soulcm commented Oct 13, 2020

image
目前我将其alias掉,编译没报错了,但不知道有没有什么其他影响

@JuSanZhi
Copy link

我也遇到同样的问题,
image

@Chen-jj
Copy link
Contributor

Chen-jj commented May 31, 2022

没有复现,Taro 内部默认的 webpack 配置是设置了 alias 的:

'regenerator-runtime': require.resolve('regenerator-runtime'),

@Chen-jj Chen-jj closed this as completed May 31, 2022
@meowmeowGuo
Copy link

没有复现,Taro 内部默认的 webpack 配置是设置了 alias 的:

'regenerator-runtime': require.resolve('regenerator-runtime'),

我这边遇到了一个问题,微信小程序编译会报找不到regenerator-runtime/runtime的错,把node_modules/@tarojs/mini-runner/dist/webpack/base.conf.js以及node_modules/@tarojs/webpack5-runner/dist/webpack/MiniBaseConfig.js 的alias的'regenerator-runtime'配置注释掉就可以了,这是什么原因呢?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F-react Framework - React T-weapp Target - 编译到微信小程序 V-3 Version - 3.x
Projects
None yet
Development

No branches or pull requests

4 participants