制作捆绑包:导入htmlWebpackPlugin的意外标识符

时间:2019-03-04 17:09:48

标签: node.js heroku npm webpack bundle

我正在尝试在Heroku上部署我的prokect,并且在编译时遇到下一个日志错误:

0 info it worked if it ends with ok
1 verbose cli [ '/opt/node-v10.12.0/bin/node',
1 verbose cli   '/opt/node-v10.12.0/bin/npm',
1 verbose cli   'run',
1 verbose cli   'compile' ]
2 info using npm@6.4.1
3 info using node@v10.12.0
4 verbose run-script [ 'precompile', 'compile', 'postcompile' ]
5 info lifecycle basketmetrics2@1.0.0~precompile: basketmetrics2@1.0.0
6 info lifecycle basketmetrics2@1.0.0~compile: basketmetrics2@1.0.0
7 verbose lifecycle basketmetrics2@1.0.0~compile: unsafe-perm in lifecycle true
8 verbose lifecycle basketmetrics2@1.0.0~compile: PATH: /opt/node-v10.12.0/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/home/josecarlos/Workspace/nodejs/basketmetrics2/node_modules/.bin:/opt/node-v10.12.0/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/home/josecarlos/Workspace/nodejs/basketmetrics2/node_modules/.bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/opt/node-v10.12.0/bin:/snap/bin
9 verbose lifecycle basketmetrics2@1.0.0~compile: CWD: /home/josecarlos/Workspace/nodejs/basketmetrics2
10 silly lifecycle basketmetrics2@1.0.0~compile: Args: [ '-c',
10 silly lifecycle   'NODE_ENV=production webpack --config ./webpack.config.js --progress' ]
11 silly lifecycle basketmetrics2@1.0.0~compile: Returned: code: 1  signal: null
12 info lifecycle basketmetrics2@1.0.0~compile: Failed to exec compile script
13 verbose stack Error: basketmetrics2@1.0.0 compile: `NODE_ENV=production webpack --config ./webpack.config.js --progress`
13 verbose stack Exit status 1
13 verbose stack     at EventEmitter.<anonymous> (/opt/node-v10.12.0/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:301:16)
13 verbose stack     at EventEmitter.emit (events.js:182:13)
13 verbose stack     at ChildProcess.<anonymous> (/opt/node-v10.12.0/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
13 verbose stack     at ChildProcess.emit (events.js:182:13)
13 verbose stack     at maybeClose (internal/child_process.js:962:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:251:5)
14 verbose pkgid basketmetrics2@1.0.0
15 verbose cwd /home/josecarlos/Workspace/nodejs/basketmetrics2
16 verbose Linux 4.10.0-38-generic
17 verbose argv "/opt/node-v10.12.0/bin/node" "/opt/node-v10.12.0/bin/npm" "run" "compile"
18 verbose node v10.12.0
19 verbose npm  v6.4.1
20 error code ELIFECYCLE
21 error errno 1
22 error basketmetrics2@1.0.0 compile: `NODE_ENV=production webpack --config ./webpack.config.js --progress`
22 error Exit status 1
23 error Failed at the basketmetrics2@1.0.0 compile script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]

这些是我在控制台中得到的结果:

remote:        Running heroku-postbuild
remote:        
remote:        > basketmetrics2@1.0.0 heroku-postbuild /tmp/build_b46aa8ee3070714e7441306fa0608096
remote:        > webpack -p
remote:        
remote: /tmp/build_b46aa8ee3070714e7441306fa0608096/webpack.config.js:2
remote: import htmlWebpackPlugin from "html-webpack-plugin";
remote:        ^^^^^^^^^^^^^^^^^
remote: 
remote: SyntaxError: Unexpected identifier
remote:     at new Script (vm.js:85:7)
remote:     at NativeCompileCache._moduleCompile (/tmp/build_b46aa8ee3070714e7441306fa0608096/node_modules/v8-compile-cache/v8-compile-cache.js:226:18)
remote:     at Module._compile (/tmp/build_b46aa8ee3070714e7441306fa0608096/node_modules/v8-compile-cache/v8-compile-cache.js:172:36)
remote:     at Object.Module._extensions..js (internal/modules/cjs/loader.js:749:10)
remote:     at Module.load (internal/modules/cjs/loader.js:630:32)
remote:     at tryModuleLoad (internal/modules/cjs/loader.js:570:12)
remote:     at Function.Module._load (internal/modules/cjs/loader.js:562:3)
remote:     at Module.require (internal/modules/cjs/loader.js:667:17)
remote:     at require (/tmp/build_b46aa8ee3070714e7441306fa0608096/node_modules/v8-compile-cache/v8-compile-cache.js:159:20)
remote:     at WEBPACK_OPTIONS (/tmp/build_b46aa8ee3070714e7441306fa0608096/node_modules/webpack-cli/bin/convert-argv.js:115:13)
remote:     at requireConfig (/tmp/build_b46aa8ee3070714e7441306fa0608096/node_modules/webpack-cli/bin/convert-argv.js:117:6)
remote:     at /tmp/build_b46aa8ee3070714e7441306fa0608096/node_modules/webpack-cli/bin/convert-argv.js:124:17
remote:     at Array.forEach (<anonymous>)
remote:     at module.exports (/tmp/build_b46aa8ee3070714e7441306fa0608096/node_modules/webpack-cli/bin/convert-argv.js:122:15)
remote:     at yargs.parse (/tmp/build_b46aa8ee3070714e7441306fa0608096/node_modules/webpack-cli/bin/cli.js:228:39)
remote:     at Object.parse (/tmp/build_b46aa8ee3070714e7441306fa0608096/node_modules/webpack-cli/node_modules/yargs/yargs.js:567:18)
remote:     at /tmp/build_b46aa8ee3070714e7441306fa0608096/node_modules/webpack-cli/bin/cli.js:206:8
remote:     at Object.<anonymous> (/tmp/build_b46aa8ee3070714e7441306fa0608096/node_modules/webpack-cli/bin/cli.js:500:3)
remote:     at Module._compile (internal/modules/cjs/loader.js:738:30)
remote:     at Object.Module._extensions..js (internal/modules/cjs/loader.js:749:10)
remote:     at Module.load (internal/modules/cjs/loader.js:630:32)
remote:     at tryModuleLoad (internal/modules/cjs/loader.js:570:12)
remote:     at Function.Module._load (internal/modules/cjs/loader.js:562:3)
remote:     at Module.require (internal/modules/cjs/loader.js:667:17)
remote:     at require (internal/modules/cjs/helpers.js:20:18)
remote:     at Object.<anonymous> (/tmp/build_b46aa8ee3070714e7441306fa0608096/node_modules/webpack/bin/webpack.js:156:2)
remote:     at Module._compile (internal/modules/cjs/loader.js:738:30)
remote:     at Object.Module._extensions..js (internal/modules/cjs/loader.js:749:10)
remote:     at Module.load (internal/modules/cjs/loader.js:630:32)
remote:     at tryModuleLoad (internal/modules/cjs/loader.js:570:12)
remote: npm ERR! code ELIFECYCLE
remote: npm ERR! errno 1
remote: npm ERR! basketmetrics2@1.0.0 heroku-postbuild: `webpack -p`
remote: npm ERR! Exit status 1
remote: npm ERR! 
remote: npm ERR! Failed at the basketmetrics2@1.0.0 heroku-postbuild script.
remote: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
remote: 
remote: npm ERR! A complete log of this run can be found in:
remote: npm ERR!     /tmp/npmcache.e5zbl/_logs/2019-03-04T16_46_47_768Z-debug.log
remote: 
remote: -----> Build failed
remote:        
remote:        We're sorry this build is failing! You can troubleshoot common issues here:
remote:        https://devcenter.heroku.com/articles/troubleshooting-node-deploys
remote:        
remote:        Some possible problems:
remote:        
remote:        - Dangerous semver range (>) in engines.node
remote:          https://devcenter.heroku.com/articles/nodejs-support#specifying-a-node-js-version
remote:        
remote:        Love,
remote:        Heroku
remote:        
remote:  !     Push rejected, failed to compile Node.js app.
remote: 
remote:  !     Push failed
remote: Verifying deploy...
remote: 
remote: !       Push rejected to basketmetrics.
remote: 

这是我的 package.json 文件:

{
  "name": "basketmetrics2",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "dev": "nodemon --exec babel-node src/server/server.js",
    "test": "echo \"Error: no test specified\" && exit 1",
    "build": "npm run clean && npm run compile",
    "clean": "rm -rf ./bundle/index.bundle.js",
    "compile": "NODE_ENV=production webpack --config ./webpack.config.js --progress",
    "start": "npm run build && node ./build/index.js",  
    "heroku-postbuild": "webpack -p"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "@babel/cli": "^7.2.3",
    "@babel/core": "^7.3.3",
    "@babel/node": "^7.2.2",
    "@babel/preset-env": "^7.3.1",
    "@babel/preset-react": "^7.0.0",
    "babel-loader": "^8.0.5",
    "babel-plugin-transform-class-properties": "^6.24.1",
    "css-loader": "^2.1.0",
    "file-loader": "^3.0.1",
    "html-webpack-plugin": "^3.2.0",
    "node-sass": "^4.11.0",
    "nodemon": "^1.18.10",
    "sass-loader": "^7.1.0",
    "style-loader": "^0.23.1",
    "url-loader": "^1.1.2",
    "webpack": "^4.29.4",
    "webpack-cli": "^3.2.3",
    "webpack-dev-middleware": "^3.5.2",
    "webpack-livereload-plugin": "^2.2.0"
  },
  "dependencies": {
    "bootstrap": "^4.3.1",
    "express": "^4.16.4",
    "jquery": "^3.3.1",
    "popper.js": "^1.14.7",
    "react": "^16.8.2",
    "react-bootstrap": "^1.0.0-beta.5",
    "react-dom": "^16.8.2"
  },
  "engines":{
    "node" : ">=10.12.0"
  }
}

这是我的 webpack.config.js 文件:

import htmlWebpackPlugin from "html-webpack-plugin";
import LiveReloadPlugin from "webpack-livereload-plugin";


export default {
    mode: "development",
    entry: "./src/client/index.js",
    output: {
        path: "./bundle",
        filename: "bundle.js"
    },
    devtool: 'eval-source-map',
    module: {
        rules: [
            {
                use: {
                    loader: "babel-loader"
                },                
                test: /\.js$/,
                exclude: /node_modules/
            },
            {
                use: ["style-loader", "css-loader"],
                test: /\.css$/
            },
            {
                test: /\.scss$/,
                use: [
                    {
                        loader: "style-loader"
                    },
                    {
                        loader: "css-loader",
                        options: {
                            sourceMap: true
                        }
                    },
                    {
                        loader: "saas-loader", 
                        options: {
                            sourceMap: true
                        }
                    }
                ]
            },
            {
                test: /\.(png|jpg|gif|svg|eot|ttf|woff|woff2)$/,
                loader: "url-loader",
                options: {
                    limit: 10000
                }
            }
        ]
    },
    plugins: [
        new htmlWebpackPlugin({
            template: "./src/client/index.html"
        }),
        new LiveReloadPlugin(),
    ]
}

我已经搜索了任何问题,但是没有找到任何东西。我是heroku和webpack的新手。这是我的第一次部署,因此我完全被这个错误迷住了。

我在做什么错了?

0 个答案:

没有答案