运行swagger项目时出现节点js错误

问题描述 投票:-2回答:1

我正在为我的项目使用swagger-ui-dist文件夹。当我通过npm run dev运行它时,它运行良好,并且可以看到所需的行为。

但是,当我将其提交到服务器时,发生了一些变化,并通过npm run dev在服务器上运行它时出现以下错误:


import path from "path";
       ^^^^

SyntaxError: Unexpected identifier
    at Module._compile (internal/modules/cjs/loader.js:723:23)
    at Module._compile (/Users/myuserName/Desktop/APIs_Clone/node_modules/pirates/lib/index.js:99:24)
    at Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Object.newLoader [as .js] (/Users/myuserName/Desktop/APIs_Clone/node_modules/pirates/lib/index.js:104:7)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Module.require (internal/modules/cjs/loader.js:692:17)

请帮助解决,在此先感谢:)

下面也是我的dev.babel.js文件代码:

const path = require("path");
import { HotModuleReplacementPlugin } from "webpack"
import configBuilder from "./_config-builder"
import styleConfig from "./stylesheets.babel"

const devConfig = configBuilder(
  {
    minimize: false,
    mangle: false,
    sourcemaps: true,
    includeDependencies: true,
  },
  {
    mode: "development",
    entry: {
      "swagger-ui-bundle": [
        "./src/polyfills.js", // TODO: remove?
        "./src/core/index.js",
      ],
      "swagger-ui-standalone-preset": [
        "./src/polyfills", // TODO: remove?
        "./src/standalone/index.js",
      ],
      "swagger-ui": "./src/style/main.scss",
    },

    performance: {
      hints: false
    },

    output: {
      library: "[name]",
      filename: "[name].js",
      chunkFilename: "[id].js",
    },

    devServer: {
      port: 4493,
      publicPath: "/",
      disableHostCheck: true, // for development within VMs
      stats: {
        colors: true,
      },
      hot: true,
      contentBase: path.join(__dirname, "../", "dev-helpers"),
      host: "0.0.0.0",
    },

    plugins: [new HotModuleReplacementPlugin()],
  }
)

// mix in the style config's plugins and loader rules

devConfig.plugins = [...devConfig.plugins, ...styleConfig.plugins]

devConfig.module.rules = [
  ...devConfig.module.rules,
  ...styleConfig.module.rules,
]

export default devConfig

请在此建议缺少的部分:)

javascript node.js swagger node-modules swagger-ui
1个回答
0
投票

Node不支持开箱即用的ES6导入。 This feature is still experimental

您有2个解决方案:

  • 使用require
const path = require("path");
© www.soinside.com 2019 - 2024. All rights reserved.