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

[ERR_REQUIRE_ESM]: Must use import to load ES Module #11483

Open
banyibala opened this issue Mar 19, 2022 · 4 comments
Open

[ERR_REQUIRE_ESM]: Must use import to load ES Module #11483

banyibala opened this issue Mar 19, 2022 · 4 comments
Labels
F-react Framework - React question Further information is requested T-weapp Target - 编译到微信小程序 V-3 Version - 3.x

Comments

@banyibala
Copy link

相关平台

微信小程序

小程序基础库: 未发布
使用框架: React

复现步骤

通过 gitee以最快方式下载taro微信小程序模版,
选择了云开发模版,
@tarojs/cli 版本为3.4.3,
在config/index中添加 const path = require('path') ;

期望结果

成功启动运行项目

实际结果

很多文件无法导入

环境信息

 Taro CLI 3.4.3 environment info:
    System:
      OS: macOS 12.1
      Shell: 5.8 - /bin/zsh
    Binaries:
      Node: 14.18.1 - ~/.nvm/versions/node/v14.18.1/bin/node
      npm: 6.14.15 - ~/.nvm/versions/node/v14.18.1/bin/npm
    npmPackages:
      @tarojs/cli: 3.4.3 => 3.4.3 
      @tarojs/components: 3.4.3 => 3.4.3 
      @tarojs/mini-runner: ^3.4.3 => 3.4.3 
      @tarojs/react: 3.4.3 => 3.4.3 
      @tarojs/runtime: 3.4.3 => 3.4.3 
      @tarojs/taro: 3.4.3 => 3.4.3 
      @tarojs/webpack-runner: 3.4.3 => 3.4.3 
      babel-preset-taro: 3.4.3 => 3.4.3 
      eslint-config-taro: 3.4.3 => 3.4.3 
      react: ^17.0.0 => 17.0.2 
      taro-ui: ^3.1.0-beta.2 => 3.1.0-beta.2 
    npmGlobalPackages:

补充信息

Error: cloud.callFunction:fail Error: errCode: -504002 functions execute fail | errMsg: Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /var/user/index.js
require() of ES modules is not supported.
require() of /var/user/index.js from /var/runtime/node12/UserFunction.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /var/user/package.json.

@taro-bot2 taro-bot2 bot added F-react Framework - React T-weapp Target - 编译到微信小程序 V-3 Version - 3.x labels Mar 19, 2022
@github-actions
Copy link
Contributor

等待热心的小伙伴解决问题中..., 有一些相关的 issues 可能帮助到你!

Thank you so much!

@Chen-jj
Copy link
Contributor

Chen-jj commented Mar 29, 2022

@banyibala 麻烦提供一下完整可复现的 Demo

@Chen-jj Chen-jj added the question Further information is requested label Mar 29, 2022
@geekact
Copy link

geekact commented Apr 20, 2022

这个问题是因为你装的package只支持ES module,而不支持commonJS。一般在这个包的某个早期版本会有兼容commonJS的版本,建议去github仓库找找看changelog

@yanwuguangjun
Copy link

#16806 我这个问题最终也提示这个错误

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

No branches or pull requests

4 participants