2***@qq.com
2***@qq.com
  • 发布:2021-02-23 21:15
  • 更新:2022-09-27 08:51
  • 阅读:6060

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

分类:uni-app

产品分类: uniapp/H5

PC开发环境操作系统: Mac

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

浏览器平台: 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(如调整后部分模块编译异常请使用方案一)

  • 7***@qq.com

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

    2021-02-25 10:44

  • DCloud_UNI_GSQ

    回复 7***@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"

    2021-03-02 11:28

  • dengzy666

    Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './dist/pinia.mjs' is not defined by "exports" in /项目路径/package.json


    linux下用cli打包h5,所有的包都报这个错, 是啥原因

    2022-11-25 12:43

1***@qq.com

1***@qq.com

降版本没用

  • DCloud_UNI_GSQ

    npm ls @babel/runtime 看下

    2021-02-26 12:02

  • 1***@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

    2021-03-01 17:24

  • DCloud_UNI_GSQ

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

    2021-03-01 17:29

1***@qq.com

1***@qq.com - 前端开发者 + linux 爱好者。热衷于前端开发技术, 熟悉 Vue,React,微信小程序,webpack,vite,babel,node,linux,nginx 等。

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

  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 安装同理
m***@163.com

m***@163.com

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

  • DCloud_UNI_GSQ

    有没有要补充的线索

    2021-02-24 10:46

  • m***@163.com

    回复 DCloud_UNI_GSQ: 我是回滚了上一次到yarn.lock解决到, 看情况估计是你们置顶的远影

    2021-02-24 19:41

  • DCloud_UNI_GSQ

    回复 m***@163.com: 好的,感谢反馈,@babel/runtime 这两天更新了 6 个版本,待其稳定后再继续追查根本原因

    2021-02-24 19:50

2***@qq.com

2***@qq.com (作者)

置顶

DCloud_UNI_GSQ
  • dengzy666

    Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './dist/pinia.mjs' is not defined by "exports" in /项目路径/package.json


    linux下用cli打包h5,所有的包都报这个错, 是啥原因

    2022-11-25 12:44

DCloud_UNI_GSQ

DCloud_UNI_GSQ

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

  • 2***@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

2***@qq.com

2***@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
5***@qq.com

5***@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',这一行 不知道会不会后续影响

实用码农

实用码农 - 只做实用用得上的代码

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

3***@qq.com

3***@qq.com

打个卡,等正式解决方案

2***@qq.com

2***@qq.com (作者)

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

7***@qq.com

7***@qq.com

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

McCallWang

McCallWang - 持续ing...

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

a***@163.com

a***@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

  • a***@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

    2021-02-27 11:20

2***@qq.com

2***@qq.com (作者)

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

  • DCloud_UNI_GSQ

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

    2021-03-01 15:48

  • m***@163.com

    回复 DCloud_UNI_GSQ: 这个问题好像已经关掉了, 请问什么时候能升级@babel/runtime呢?

    2021-03-21 21:50

  • DCloud_UNI_GSQ

    回复 m***@163.com: 你先升级试试

    2021-03-22 15:01

flyio

flyio

@DCloud_UNI_GSQ 这都9月份了,咋还是报这个错误。。。还没解决???

  • DCloud_UNI_GSQ

    详细描述一下

    2022-10-09 14:48

  • xionghaizhi

    十月份还报呢

    2022-10-15 16:53

  • xionghaizhi

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

    +-- @dcloudio/uni-quickapp-native@2.0.1-36420220922003

    | +-- @hap-toolkit/dsl-vue@0.6.13

    | | -- @hap-toolkit/packager@0.6.15 | |-- @babel/runtime@7.12.18 deduped

    | +-- @hap-toolkit/packager@0.6.13

    | | +-- @babel/preset-env@7.19.4

    | | | -- @babel/plugin-transform-regenerator@7.18.6 | | |-- regenerator-transform@0.15.0

    | | | -- @babel/runtime@7.12.18 deduped | |-- @babel/runtime@7.12.18 deduped

    | -- @hap-toolkit/server@0.6.13 |-- @babel/runtime@7.12.18 deduped

    -- @vue/cli-plugin-babel@5.0.8 -- @vue/babel-preset-app@5.0.8

    `-- @babel/runtime@7.12.18 deduped


    不注释掉 modules: 'commonjs' 就一直报错

    Uncaught ReferenceError: exports is not defined

    at 1541 (chunk-vendors.afdd3caa.js:7:704777)

    at o (index.19f2bf72.js:1:5928)

    at 637 (index.19f2bf72.js:1:5611)

    at o (index.19f2bf72.js:1:5928)

    at index.19f2bf72.js:1:9313

    at o.O (index.19f2bf72.js:1:6349)

    at index.19f2bf72.js:1:9327

    at index.19f2bf72.js:1:9333

    2022-10-15 16:55

  • DCloud_UNI_GSQ

    回复 xionghaizhi: 新建一个工程测试一下

    2022-10-18 14:53

该问题目前已经被锁定, 无法添加新回复