Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js:尝试运行生产构建时会出现以下错误:从";导入“承诺”/core js/promise“;;SyntaxError:意外的标识符_Node.js_Babeljs_Hapijs_Core Js - Fatal编程技术网

Node.js:尝试运行生产构建时会出现以下错误:从";导入“承诺”/core js/promise“;;SyntaxError:意外的标识符

Node.js:尝试运行生产构建时会出现以下错误:从";导入“承诺”/core js/promise“;;SyntaxError:意外的标识符,node.js,babeljs,hapijs,core-js,Node.js,Babeljs,Hapijs,Core Js,我有一个带有Vue前端的hapi.js后端(使用Vue CLI)。我正在Ubuntu 16.04上使用节点版本12.10.0 在开发模式下,一切正常。当我通过构建过程运行我的应用程序时,它构建时没有任何错误。当我尝试在生产环境中运行我的应用程序时,就会出现问题。以下是我的NPM脚本: "scripts": { "dev": "npm-run-all --parallel dev:vue dev:hapi", "dev:vue": "vue-cli-service serve", "d

我有一个带有Vue前端的hapi.js后端(使用Vue CLI)。我正在Ubuntu 16.04上使用节点版本12.10.0

在开发模式下,一切正常。当我通过构建过程运行我的应用程序时,它构建时没有任何错误。当我尝试在生产环境中运行我的应用程序时,就会出现问题。以下是我的NPM脚本:

"scripts": {
  "dev": "npm-run-all --parallel dev:vue dev:hapi",
  "dev:vue": "vue-cli-service serve",
  "dev:hapi": "NODE_ENV=development node-dev --no-notify src/server/server.js --exec babel-node",
  "build": "npm-run-all --serial build:vue build:hapi",
  "build:vue": "vue-cli-service build",
  "build:hapi": "NODE_ENV=production babel src/server --out-dir dist/server --copy-files",
  "prod": "NODE_ENV=production node dist/server/server.js",
  ...
}
运行
npm run prod
后,我的终端出现以下错误:

/path/to/node_modules/@babel/runtime-corejs2/helpers/esm/asyncToGenerator.js:1
import _Promise from "../../core-js/promise";
       ^^^^^^^^

SyntaxError: Unexpected identifier
这是我的
babel.config.js
文件:

module.exports = {
  presets: [
    "@vue/app",
    "@babel/preset-env",
  ],
  plugins: [
    ["@babel/plugin-transform-runtime", {
      corejs: 2,
    }]
  ]
};
我以为
@babel/plugin transform runtime
插件应该能够处理我可能遇到的任何问题。显然,节点v12应该支持开箱即用的承诺,但我显然仍然有问题

有人知道在这种情况下发生了什么,我能做些什么来解决它吗


谢谢大家!

我终于找到了答案。我不得不更改我的
babel.config.js
文件中的配置。我为客户机和服务器包括和定义了单独的配置。这就是我的
babel.config.js
文件现在的样子:

module.exports = {
  env: {
    client: {
      presets: [
        "@vue/app",
      ]
    },
    server: {
      presets: [
        "@babel/preset-env",
      ],
      plugins: [
        ["@babel/plugin-transform-runtime", {
          corejs: 2,
        }]
      ]
    }
  }
};