微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Windows 操作系统上的 vue + core-js:无法分配给对象“#<Object>”的只读属性“exports”

如何解决Windows 操作系统上的 vue + core-js:无法分配给对象“#<Object>”的只读属性“exports”

我无法在 Windows 机器上构建 Vue 应用程序,但我可以在 Linux 机器上构建它而不会出现问题。我已经尝试了所有可以在网上找到并且适用于我的案例的解决方案,但没有任何效果

    ERROR  Failed to compile with 1 errors

    Error: C:\Users\Administrator\www\app\fe/node_modules/core-js/modules/_is-object.js?:5
    module.exports = function (it) {
                    ^
    TypeError: Cannot assign to read only property 'exports' of object '#<Object>'

    - _is-object.js?:5 Module.eval
        [.]/[core-js]/modules/_is-object.js?:5:16

    - _is-object.js?:8 eval
        [.]/[core-js]/modules/_is-object.js?:8:30

    - index.html:1136 Module../node_modules/core-js/modules/_is-object.js
        C:/Users/Administrator/www/app/fe/public/index.html:1136:1

    - index.html:21 __webpack_require__
        C:/Users/Administrator/www/app/fe/public/index.html:21:30

    - _inherit-if-required.js?:1 eval
        [.]/[core-js]/modules/_inherit-if-required.js?:1:16

    - index.html:1112 Object../node_modules/core-js/modules/_inherit-if-required.js
        C:/Users/Administrator/www/app/fe/public/index.html:1112:1

    - index.html:21 __webpack_require__
        C:/Users/Administrator/www/app/fe/public/index.html:21:30

    - es6.regexp.constructor.js?:3 eval
        [.]/[core-js]/modules/es6.regexp.constructor.js?:3:25

    - index.html:1623 Object../node_modules/core-js/modules/es6.regexp.constructor.js
        C:/Users/Administrator/www/app/fe/public/index.html:1623:1

    - index.html:21 __webpack_require__
        C:/Users/Administrator/www/app/fe/public/index.html:21:30


        ERROR  Build Failed with errors.
        npm ERR! code ELIFECYCLE
        npm ERR! errno 1
        npm ERR! app@0.1.0 build: `vue-cli-service build "--mode=test"`
        npm ERR! Exit status 1
    npm ERR!
    npm ERR! Failed at the app@0.1.0 build script.
    npm ERR! This is probably not a problem with npm. There is likely additional logging 
    output above.

    npm ERR! A complete log of this run can be found in:
    npm ERR!     C:\Users\Administrator\AppData\Roaming\npm-cache\_logs\2021-06-26T06_48_04_957Z-debug.log
    PS C:\Users\Administrator\www\app\fe>

这是 package.json

    {
      "name": "app","version": "0.1.0","private": true,"scripts": {
        "serve": "vue-cli-service serve","build": "vue-cli-service build","lint": "vue-cli-service lint","lint:style": "vue-cli-service lint:style --no-fix","lint:style:fix": "vue-cli-service lint:style"
      },"dependencies": {
        "apexcharts": "^3.25.0","axios": "^0.19.0","babel-polyfill": "^6.26.0","core-js": "^2.6.12","filepond": "^4.25.1","marked": "^1.2.9","moment": "^2.29.1","register-service-worker": "^1.7.2","text-mask-addons": "^3.8.0","v-calendar": "^0.9.7","vee-validate": "^2.2.13","veLocity-animate": "^1.5.2","vue": "^2.6.12","vue-apexcharts": "^1.6.0","vue-filepond": "^5.1.2","vue-Meta": "^2.4.0","vue-router": "^3.5.1","vue-router-multiguard": "^1.0.3","vue-text-mask": "^6.1.2","vue2-datepicker": "^2.12.0","vue2-notify": "^1.4.0","vuedraggable": "^2.24.3","vuex": "^3.6.2","vuex-i18n": "^1.13.1"
      },"devDependencies": {
        "@ascendancyy/vue-cli-plugin-stylelint": "^1.1.2","@babel/plugin-transform-shorthand-properties": "^7.12.13","@babel/preset-env": "^7.12.16","@vue/cli-plugin-babel": "^3.9.0","@vue/cli-plugin-eslint": "^3.9.0","@vue/cli-plugin-pwa": "^3.9.0","@vue/cli-service": "^3.9.0","@vue/eslint-config-standard": "^4.0.0","autoprefixer": "^9.8.6","babel-eslint": "^10.0.1","babel-plugin-transform-es2015-template-literals": "^6.22.0","eslint": "^6.6.0","eslint-plugin-jsdoc": "^17.1.0","eslint-plugin-strict-vue": "^1.0.0","eslint-plugin-vue": "^5.0.0","lint-staged": "^8.1.5","node-sass": "^4.14.1","sass-loader": "^7.1.0","stylelint": "^11.1.1","stylelint-config-standard": "^18.2.0","stylelint-scss": "^3.19.0","vue-template-compiler": "^2.6.12","webpack-notifier": "^1.13.0"
      }
    }

我已经花了很多时间,但我正在失去它。 该项目最初是在两年前在 Linux 上构建的,我从未遇到任何问题。现在我有一个新客户,那里的人想要在 Windows 机器上运行该应用程序,所以我别无选择。

解决方法

我已经解决了。问题似乎出在 vue.config.js 文件中的 webpack 规则中。我删除了它,然后我可以构建应用程序。

module.exports = {
    ...
    configureWebpack: {
        ...
        module: {
            rules: [
            // THIS PART WAS REMOVED AND I CAN NOW BUILD THE APP
            {
                test: /\.(js|jsx)$/,use: [
                    {
                        loader: "babel-loader"
                    }
                ],// Exclude the untransformed packages from the exclude rule here
                exclude: /node_modules\/(?!(@mypackage\/mypackage)\/).*/
            }
        ]
    }
    ...
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。