250655604@qq.com
250655604@qq.com
  • 发布:2021-02-23 21:15
  • 更新:4 天前
  • 阅读:679

【报Bug】uniapp cli 启动 H5 提示 exports is not defined

分类:uni-app

产品分类: uniapp/H5

PC开发环境操作系统: Mac

PC开发环境操作系统版本号: big sug

HBuilderX类型: 正式

浏览器平台: Chrome

浏览器版本: null

项目创建方式: CLI

CLI版本号: 2.0.0-31220210205004

操作步骤:

npm run dev:h5

预期结果:

不报错

实际结果:

不报错

bug描述:

chunk-vendors.js:58 Uncaught ReferenceError: exports is not defined
at Module../node_modules/@babel/runtime/helpers/objectSpread2/_index.mjs (chunk-vendors.js:58)
at webpack_require__ (index.js:854)
at fn (index.js:151)
at Object../node_modules/@babel/runtime/helpers/esm/objectSpread2.js (chunk-vendors.js:23)
at
webpack_require (index.js:854)
at fn (index.js:151)
at eval (main.js:5)
at Object../src/main.js (index.js:1214)
at
webpack_require__ (index.js:854)
at fn (index.js:151)

2021-02-23 21:15 负责人:无 分享
已邀请:

最佳回复

DCloud_UNI_GSQ

DCloud_UNI_GSQ

问题原因:@babel/runtime 昨天更新到了 7.13.x,有较大改动,引起兼容问题

目前已经更新 preset,对已经安装了新版本 @babel/runtime 的用户提供以下两种解决方案:

一、回退 @babel/runtime 版本

删除 node_modules 目录和 package-lock.json 文件,在 package.json 文件中增加开发依赖 "@babel/runtime": "~7.12.0",执行 npm install 重新安装依赖即可

二、修改 babel 配置

打开 babel.config.js 文件,删除或注释掉 babel.config.js(如调整后部分模块编译异常请使用方案一)

  • 734204679@qq.com

    我部署到服务器是用yarn 打包能正常访问,npm打包就是报 exports is not defined;用这个方法解决了。昨天项目挂了一下午了

    2021-02-25 10:44

  • DCloud_UNI_GSQ

    回复 734204679@qq.com: 恩,应该是你 yarn.lock 中记录的版本是正常版本

    2021-02-25 10:46

  • 种子的信仰

    按照 "一、回退 @babel/runtime 版本" 这里操作之后, yarn.lock 里面仍然有 "7.13.8"的版本, 前前后后搞了好久非常无奈, 暂时手动把yarn.lock里面的 version "7.13.8" 改成 version "7.12.18" 用着先了

    "@babel/runtime@7.12.0":

    version "7.12.0"

    resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.12.0.tgz#98bd7666186969c04be893d747cf4a6c6c8fa6b0"

    integrity sha512-lS4QLXQ2Vbw2ubfQjeQcn+BZgZ5+ROHW9f+DWjEp5Y+NHYmkRGKqHSJ1tuhbUauKu2nhZNTBIvsIQ8dXfY5Gjw==

    dependencies:

    regenerator-runtime "^0.13.4"


    "@babel/runtime@^7.0.0", "@babel/runtime@^7.11.0", "@babel/runtime@^7.8.4":

    version "7.13.8"

    resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.13.8.tgz#cc886a85c072df1de23670dc1aa59fc116c4017c"

    integrity sha512-CwQljpw6qSayc0fRG1soxHAKs1CnQMOChm4mlQP6My0kf9upVGizj/KhlTTgyUnETmHpcUXjaluNAkteRFuafg==

    dependencies:

    regenerator-runtime "^0.13.4"

    3 天前

1446628111@qq.com

1446628111@qq.com

我刚试了,这样解决可以保证不会有版本问题

  1. package.json 中添加 "@babel/runtime": "7.11.2"
  2. 用yarn下载依赖
  3. 下载完成后,修改yarn.lock中的@babel/runtime 的版本 全文件搜索 我用的vant 源码里的依赖是 "@babel/runtime" "7.x" 这个会下载最新的版本,直接改成 "@babel/runtime" "7.0.0" ,其他的大于7.13.0的版本全部改成小于7.12.0的版本,我这里是改成7.11.2
  4. 然后删除node_modules
  5. 然后再用yarn 下载
  6. npm 安装同理
muzaisimao@163.com

muzaisimao@163.com

我也遇到了这个问题, 前一个小时还不会, 突然就这样了, 求解.

250655604@qq.com

250655604@qq.com (作者)

置顶

DCloud_UNI_GSQ
DCloud_UNI_GSQ

DCloud_UNI_GSQ

使用 npm run info 打印一下依赖信息回复我

  • 250655604@qq.com (作者)

    uni-app v3.1.2

    uni-app cli v2.0.0-31220210205004


    Environment Info:


    System:

    OS: macOS 11.0.1

    CPU: (4) x64 Intel(R) Core(TM) i5-7500 CPU @ 3.40GHz

    Binaries:

    Node: 14.12.0 - /var/folders/0h/3dh7y0v107x__hfdqqttwj_00000gn/T/yarn--1614136603029-0.4053797691650989/node

    Yarn: 1.22.10 - /var/folders/0h/3dh7y0v107x__hfdqqttwj_00000gn/T/yarn--1614136603029-0.4053797691650989/yarn

    npm: 6.14.8 - /usr/local/bin/npm

    Browsers:

    Chrome: 88.0.4324.192

    Firefox: Not Found

    Safari: 14.0.1

    npmPackages:

    @dcloudio/uni-app-plus: 2.0.0-31220210205004 => 2.0.0-31220210205004

    @dcloudio/uni-app-plus-nvue: 0.0.1

    @dcloudio/uni-app-plus-nvue-v8: 0.0.1

    @dcloudio/uni-automator: 2.0.0-31220210205004 => 2.0.0-31220210205004

    @dcloudio/uni-cli-shared: 2.0.0-31220210205004 => 2.0.0-31220210205004

    @dcloudio/uni-h5: 2.0.0-31220210205004 => 2.0.0-31220210205004

    @dcloudio/uni-helper-json: 1.0.13 => 1.0.13

    @dcloudio/uni-migration: 2.0.0-31220210205004 => 2.0.0-31220210205004

    @dcloudio/uni-mp-vue: 2.0.0-31220210205004 => 2.0.0-31220210205004

    @dcloudio/uni-mp-weixin: 2.0.0-31220210205004 => 2.0.0-31220210205004

    @dcloudio/uni-stat: 2.0.0-31220210205004 => 2.0.0-31220210205004

    @dcloudio/uni-template-compiler: 2.0.0-31220210205004 => 2.0.0-31220210205004

    @dcloudio/vue-cli-plugin-hbuilderx: 2.0.0-31220210205004 => 2.0.0-31220210205004

    @dcloudio/vue-cli-plugin-uni: 2.0.0-31220210205004 => 2.0.0-31220210205004

    @dcloudio/vue-cli-plugin-uni-optimize: 2.0.0-31220210205004 => 2.0.0-31220210205004

    @dcloudio/webpack-uni-mp-loader: 2.0.0-31220210205004 => 2.0.0-31220210205004

    @dcloudio/webpack-uni-nvue-loader: 0.0.1

    @dcloudio/webpack-uni-pages-loader: 2.0.0-31220210205004 => 2.0.0-31220210205004

    @vue/babel-helper-vue-jsx-merge-props: 1.2.1

    @vue/babel-helper-vue-transform-on: 1.0.2

    @vue/babel-plugin-jsx: 1.0.3

    @vue/babel-plugin-transform-vue-jsx: 1.2.1

    @vue/babel-preset-app: 4.5.11

    @vue/babel-preset-jsx: 1.2.4

    @vue/babel-sugar-composition-api-inject-h: 1.2.1

    @vue/babel-sugar-composition-api-render-instance: 1.2.4

    @vue/babel-sugar-functional-vue: 1.2.2

    @vue/babel-sugar-inject-h: 1.2.2

    @vue/babel-sugar-v-model: 1.2.3

    @vue/babel-sugar-v-on: 1.2.3

    @vue/cli-overlay: 4.5.11

    @vue/cli-plugin-babel: 4.5.11 => 4.5.11

    @vue/cli-plugin-eslint: 4.5.11 => 4.5.11

    @vue/cli-plugin-router: 4.5.11

    @vue/cli-plugin-vuex: 4.5.11

    @vue/cli-service: 4.5.11 => 4.5.11

    @vue/cli-shared-utils: 4.5.11

    @vue/component-compiler-utils: 3.2.0 (3.2.0)

    @vue/composition-api: 1.0.0-rc.2 => 1.0.0-rc.2

    @vue/eslint-config-prettier: 6.0.0 => 6.0.0

    @vue/preload-webpack-plugin: 1.1.2

    @vue/web-component-wrapper: 1.3.0

    eslint-plugin-vue: 7.6.0 => 7.6.0

    mpvue-page-factory: 1.0.1

    mpvue-template-compiler: 1.0.13

    uni-h5-vue: 2.6.10

    uni-mp-vue: 2.6.10

    vue: 2.6.12 => 2.6.12

    vue-eslint-parser: 7.5.0

    vue-hot-reload-api: 2.3.4

    vue-i18n: 8.22.4 => 8.22.4

    vue-loader: 15.9.6 (16.1.2, 15.9.6)

    vue-router: 3.0.1

    vue-style-loader: 4.1.2

    vue-template-compiler: 2.6.12 => 2.6.12 (2.6.12)

    vue-template-es2015-compiler: 1.9.1

    vuex: 3.6.2 => 3.6.2

    vuex-persistedstate: 4.0.0-beta.3 => 4.0.0-beta.3

    npmGlobalPackages:

    @vue/cli: Not Found

    2021-02-24 11:35

250655604@qq.com

250655604@qq.com (作者)

uni-app v3.1.2  
uni-app cli v2.0.0-31220210205004  

Environment Info:  

  System:  
    OS: macOS 11.0.1  
    CPU: (4) x64 Intel(R) Core(TM) i5-7500 CPU @ 3.40GHz  
  Binaries:  
    Node: 14.12.0 - /var/folders/0h/3dh7y0v107x__hfdqqttwj_00000gn/T/yarn--1614136603029-0.4053797691650989/node  
    Yarn: 1.22.10 - /var/folders/0h/3dh7y0v107x__hfdqqttwj_00000gn/T/yarn--1614136603029-0.4053797691650989/yarn  
    npm: 6.14.8 - /usr/local/bin/npm  
  Browsers:  
    Chrome: 88.0.4324.192  
    Firefox: Not Found  
    Safari: 14.0.1  
  npmPackages:  
    @dcloudio/uni-app-plus: 2.0.0-31220210205004 => 2.0.0-31220210205004   
    @dcloudio/uni-app-plus-nvue:  0.0.1   
    @dcloudio/uni-app-plus-nvue-v8:  0.0.1   
    @dcloudio/uni-automator: 2.0.0-31220210205004 => 2.0.0-31220210205004   
    @dcloudio/uni-cli-shared: 2.0.0-31220210205004 => 2.0.0-31220210205004   
    @dcloudio/uni-h5: 2.0.0-31220210205004 => 2.0.0-31220210205004   
    @dcloudio/uni-helper-json: 1.0.13 => 1.0.13   
    @dcloudio/uni-migration: 2.0.0-31220210205004 => 2.0.0-31220210205004   
    @dcloudio/uni-mp-vue: 2.0.0-31220210205004 => 2.0.0-31220210205004   
    @dcloudio/uni-mp-weixin: 2.0.0-31220210205004 => 2.0.0-31220210205004   
    @dcloudio/uni-stat: 2.0.0-31220210205004 => 2.0.0-31220210205004   
    @dcloudio/uni-template-compiler: 2.0.0-31220210205004 => 2.0.0-31220210205004   
    @dcloudio/vue-cli-plugin-hbuilderx: 2.0.0-31220210205004 => 2.0.0-31220210205004   
    @dcloudio/vue-cli-plugin-uni: 2.0.0-31220210205004 => 2.0.0-31220210205004   
    @dcloudio/vue-cli-plugin-uni-optimize: 2.0.0-31220210205004 => 2.0.0-31220210205004   
    @dcloudio/webpack-uni-mp-loader: 2.0.0-31220210205004 => 2.0.0-31220210205004   
    @dcloudio/webpack-uni-nvue-loader:  0.0.1   
    @dcloudio/webpack-uni-pages-loader: 2.0.0-31220210205004 => 2.0.0-31220210205004   
    @vue/babel-helper-vue-jsx-merge-props:  1.2.1   
    @vue/babel-helper-vue-transform-on:  1.0.2   
    @vue/babel-plugin-jsx:  1.0.3   
    @vue/babel-plugin-transform-vue-jsx:  1.2.1   
    @vue/babel-preset-app:  4.5.11   
    @vue/babel-preset-jsx:  1.2.4   
    @vue/babel-sugar-composition-api-inject-h:  1.2.1   
    @vue/babel-sugar-composition-api-render-instance:  1.2.4   
    @vue/babel-sugar-functional-vue:  1.2.2   
    @vue/babel-sugar-inject-h:  1.2.2   
    @vue/babel-sugar-v-model:  1.2.3   
    @vue/babel-sugar-v-on:  1.2.3   
    @vue/cli-overlay:  4.5.11   
    @vue/cli-plugin-babel: 4.5.11 => 4.5.11   
    @vue/cli-plugin-eslint: 4.5.11 => 4.5.11   
    @vue/cli-plugin-router:  4.5.11   
    @vue/cli-plugin-vuex:  4.5.11   
    @vue/cli-service: 4.5.11 => 4.5.11   
    @vue/cli-shared-utils:  4.5.11   
    @vue/component-compiler-utils:  3.2.0 (3.2.0)  
    @vue/composition-api: 1.0.0-rc.2 => 1.0.0-rc.2   
    @vue/eslint-config-prettier: 6.0.0 => 6.0.0   
    @vue/preload-webpack-plugin:  1.1.2   
    @vue/web-component-wrapper:  1.3.0   
    eslint-plugin-vue: 7.6.0 => 7.6.0   
    mpvue-page-factory:  1.0.1   
    mpvue-template-compiler:  1.0.13   
    uni-h5-vue:  2.6.10   
    uni-mp-vue:  2.6.10   
    vue: 2.6.12 => 2.6.12   
    vue-eslint-parser:  7.5.0   
    vue-hot-reload-api:  2.3.4   
    vue-i18n: 8.22.4 => 8.22.4   
    vue-loader:  15.9.6 (16.1.2, 15.9.6)  
    vue-router:  3.0.1   
    vue-style-loader:  4.1.2   
    vue-template-compiler: 2.6.12 => 2.6.12 (2.6.12)  
    vue-template-es2015-compiler:  1.9.1   
    vuex: 3.6.2 => 3.6.2   
    vuex-persistedstate: 4.0.0-beta.3 => 4.0.0-beta.3   
  npmGlobalPackages:  
    @vue/cli: Not Found
598451997@qq.com

598451997@qq.com

我这边也是同样的问题,求大佬快点提出解决方案

colorS

colorS

我这边也是同样的问题,希望官方大大尽快提出解决方案。

a_gou

a_gou

module.exports = {
presets: [
[
'@vue/app',
{
// modules: 'commonjs',
useBuiltIns: process.env.UNI_PLATFORM === 'h5' ? 'usage' : 'entry'
}
]
],
plugins
}

我司大佬的解决方案: 在babel.config.js 中 注释掉 modules: 'commonjs',这一行 不知道会不会后续影响

892156860@qq.com

892156860@qq.com

可以了吗?,我也是 在babel.config.js 中 注释掉 modules: 'commonjs',这一行,才可以,什么问题啊???

390656347@qq.com

390656347@qq.com

打个卡,等正式解决方案

250655604@qq.com

250655604@qq.com (作者)

@babel/runtime : 7.12.5 还是提示报错

734204679@qq.com

734204679@qq.com

我也是有这个问题 只不过是在部署的时候出现

McCallWang

McCallWang - 持续ing...

同样问题加一,哈哈哈刚入门uniapp,准备开始学习

1054535289@qq.com

1054535289@qq.com

降版本没用

  • DCloud_UNI_GSQ

    npm ls @babel/runtime 看下

    2021-02-26 12:02

  • 1054535289@qq.com

    回复 DCloud_UNI_GSQ: +-- @babel/runtime@7.12.0

    +-- @vue/cli-plugin-babel@4.5.11

    | -- @vue/babel-preset-app@4.5.11 | +-- @babel/preset-env@7.13.5 | |-- @babel/plugin-transform-regenerator@7.12.13

    | | -- regenerator-transform@0.14.5 | |-- @babel/runtime@7.13.7

    | -- @babel/runtime@7.13.7 -- babel-plugin-import@1.13.3

    `-- @babel/runtime@7.13.7


    依然exports is not defined

    4 天前

  • DCloud_UNI_GSQ

    回复 1054535289@qq.com: 你用的是 7.13.7,按置顶帖子处理

    4 天前

a18507332450@163.com

a18507332450@163.com

目前我用的@babel/runtime版本是7.12.5,但是还是报错;注释掉 modules: 'commonjs',这一行也不行

  • DCloud_UNI_GSQ

    你的版本不可能是 7.12.5,7.12.5 中没有 mjs 文件,npm ls @babel/runtime 看下

    2021-02-26 16:23

  • a18507332450@163.com

    回复 DCloud_UNI_GSQ: mall.member. uniapp@1.0.0 C:\Users \Administrator\Desktop\新建文件夹((5) \member. uniapp十一一 @vue/cli-plugin-babe1@4.5.9

    l -- @vue/babel-preset-app@4.5.9

    +—— @babel/preset-env@7.12.7

    l~-- @babe1/plugin-transform-regenerator@7.12.1

    '-- regenerator-transform@0.14.5

    `--@babel/runtime@7.12.5deduped'--@babel/runtime@7.12.5deduped


    • babel-plugin-import@1.13.3

      ~--@babe1/runtime@7.12.5

    6 天前

250655604@qq.com

250655604@qq.com (作者)

什么时候才能正式解决 @babel/runtime 最近更新已经稳定了

  • DCloud_UNI_GSQ

    看了一下 babel 近期的更新,一直在尝试修复这个问题,但是修复的不是很利索,来自官方成员的一个建议是固定版本未 7.12。https://github.com/babel/babel/issues/12902#issuecomment-785741602

    4 天前

要回复问题请先登录注册