【问题标题】:Uncaught TypeError: [] is not a function未捕获的 TypeError:[] 不是函数
【发布时间】:2019-12-01 06:17:31
【问题描述】:

我正在使用 vue js 2.6.10,就在我在 npm 上更新我的所有包之后,我的应用程序在生产环境中根本无法运行......它在开发环境中运行良好

错误是

Uncaught TypeError: [] is not a function

当我检查源代码时,错误来自这个

), [], !1, null, null, null).exports
      , va = []((function() {
        if ("undefined" != typeof document) {
            var t = document.head || document.getElementsByTagName("head")[0]
              , e = document.createElement("style")
              , a = " a[data-v-11b2e33f] { cursor: pointer; } ";
            e.type = "text/css",
            e.styleSheet ? e.styleSheet.cssText = a : e.appendChild(document.createTextNode(a)),
            t.appendChild(e)
        }
    }

我不知道这是什么意思。我尝试进行 npm install 和 npm update 以确保所有内容都相应更新但仍然没有运气

这是我的 vue 应用 package.json(也许这会有所帮助)

{
    "private": true,
    "scripts": {
        "dev": "npm run development",
        "development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
        "watch": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --watch --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
        "watch-poll": "npm run watch -- --watch-poll",
        "hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
        "prod": "npm run production",
        "production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
    },
    "devDependencies": {
        "axios": "^0.19.0",
        "bootstrap": "^4.4.1",
        "cross-env": "^5.2.1",
        "jquery": "^3.4.1",
        "laravel-mix": "^5.0.0",
        "lodash": "^4.17.15",
        "popper.js": "^1.16.0",
        "resolve-url-loader": "^3.1.1",
        "sass": "^1.23.7",
        "sass-loader": "^8.0.0",
        "vue": "^2.6.10",
        "vue-template-compiler": "^2.6.10"
    },
    "dependencies": {
        "@ckeditor/ckeditor5-build-classic": "^15.0.0",
        "echarts": "^4.5.0",
        "fibers": "^4.0.2",
        "file-saver": "^2.0.2",
        "hooper": "^0.3.4",
        "katex": "^0.10.2",
        "laravel-vue-pagination": "^2.3.1",
        "moment": "^2.24.0",
        "node-sass": "^4.13.0",
        "v-tooltip": "^2.0.2",
        "vee-validate": "^2.2.15",
        "vue-ckeditor5": "^0.4.1",
        "vue-cleave-component": "^2.1.3",
        "vue-context-menu": "^2.0.6",
        "vue-echarts": "^4.0.4",
        "vue-echarts-v3": "^2.0.1",
        "vue-json-excel": "^0.2.98",
        "vue-katex": "^0.3.0",
        "vue-router": "^3.1.3",
        "vue-truncate-collapsed": "^2.1.0",
        "vue2-filters": "^0.8.0",
        "vuex": "^3.1.2"
    }
}

【问题讨论】:

  • 在出现此问题之前您更新了哪些软件包?
  • 除了 vue 和 vue-template-compiler 之外几乎都在 devDependencies 上
  • 您是否尝试过在 Webpack 中禁用最小化以查看是否可以解决问题?
  • 怎么做?
  • 你应该有一个webpack.config.js。如果已经存在,请添加或将其设置为false:optimization: { minimize: false }。

标签: javascript vue.js npm


【解决方案1】:
), [], !1, null, null, null).exports
      , va = []((function() {
        if ("undefined" != typeof document) {
            var t = document.head || document.getElementsByTagName("head")[0]
              , e = document.createElement("style")
              , a = " a[data-v-11b2e33f] { cursor: pointer; } ";
            e.type = "text/css",
            e.styleSheet ? e.styleSheet.cssText = a : e.appendChild(document.createTextNode(a)),
            t.appendChild(e)
        }
    }

我认为第 2 行有问题。 []后面不应该有任何语句,所以[]后面应该加上换行符

类似的东西

va = [];((function() {
...

【讨论】:

  • 我不认为这是 OP 编写的代码。它只是在生产中,它似乎是缩小的代码。
  • 那么我该如何解决呢?我的意思是这段代码是通过运行 npm run prod 自动生成的......并且它工作正常是我在做 npm run watch 或 npm run dev
  • 您是否尝试在源代码中与此问题对应的行添加;并重新生成?
  • 我不知道我应该在源代码中的哪里添加这些标记......而且我认为这与我的源代码无关,但更多的是关于我的包或有什么不对的地方npm 构建?
  • 你的意思是这些行来自外部库?
猜你喜欢
  • 2017-05-15
  • 2020-04-15
  • 1970-01-01
  • 1970-01-01
  • 2020-10-05
  • 2019-09-15
  • 2018-12-21
  • 2018-11-12
  • 2022-01-18
相关资源
最近更新 更多