我第一次尝试在Windows 10上使用Node和Babel (这也是我第一次使用Babel )。我认为我已经配置好了所有的东西,但它给了我一个神秘的错误:

如果我做npx webpack --exec bable-node,也会发生同样的事情。
在我所读到的每一篇文章中,它都给出了一个行号。我不知道有什么问题。
我认为所有与Node相关的文件都在一个名为“节点”的文件夹中,所有其他文件都在一个名为"src“的文件夹中。我不知道这是不是引起问题的原因。以下是文件夹结构:
/node
/config
/node_modules
.babelrc
master-updated.sh
package-lock.json
package.json
server2.js
webpack.config.js
/src
/model (this is has a bunch of js files, but I removed the references to them for now)
/public
/html
/srcipts
/stylesheets
/css
/scss
/vue
.gitignoremaster-updated.sh是一个用于响应GitHub web钩子的shell脚本。
这里是server2.js的开始
'use strict';
process.env.NODE_CONFIG_DIR = './node/config';
const config = require('config'),
babel = require('babel-core'),
ejs = require('ejs'),
util = require('util'),
express = require('express'),
bodyParser = require('body-parser'),
cors = require('cors'),
moment = require('moment'),
plaid = require('plaid'),
mariadb = require('mariadb'),
fs = require('fs'),
http = require('http'),
https = require('https'),
session = require('express-session'),
exec = require('child_process').exec;
const GOOGLE_AUTH_CLIENT_ID = '<REDACTED>';
const { OAuth2Client } = require('google-auth-library');
const googleAuthClient = new OAuth2Client(GOOGLE_AUTH_CLIENT_ID);
const APP_PORT = config.APP_PORT;这是我的webpack.config.js文件:
module.exports = {
target: 'node',
entry: {
app: ['./server2.js']
},
output: {
filename: 'server.js',
path: path.resolve(__dirname, 'test')
},
module: {
loaders: [
test: '/\.js$/',
loader: 'babel-loader',
exclude: /node_modules/,
query: {
presets: ["@babel/preset-env"]
}
]
}
}这是.babelrc
{"presets": ["@babel/preset-env"]}
这是package.json
{
"name": "sage-savings",
"version": "0.0.1",
"description": "An app for easy budgeting.",
"main": "server2.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "webpack --config node/webpack.config.js",
"start": "node node/server2.js"
},
"author": "Dakota Dalton",
"repository": "https://github.com/1silvertiger/Sage",
"license": "ISC",
"dependencies": {
"@types/express": "^4.16.1",
"aws-sdk": "^2.397.0",
"body-parser": "^1.18.3",
"config": "^3.0.1",
"cors": "^2.8.5",
"ejs": "^2.5.9",
"express": "4.16.x",
"express-session": "^1.15.6",
"google-auth-library": "^3.0.1",
"mariadb": "^2.0.3",
"moment": "^2.22.2",
"mysql": "^2.16.0",
"plaid": "2.x.x"
},
"devDependencies": {
"@babel/core": "^7.3.4",
"@babel/preset-env": "^7.3.4",
"ajv": "^6.10.0",
"babel-core": "^6.26.3",
"babel-loader": "^8.0.5",
"babel-preset-env": "^1.7.0",
"typescript": "^3.3.3333",
"webpack": "^4.29.6",
"webpack-cli": "^3.2.3"
}
}发布于 2019-03-14 15:48:36
如果使用具有突出显示语法的IDE (例如VS码 ),则很容易识别这些语法问题。我所做的就是将您的配置复制到一个文件中,并将其加载到VS代码中。
exclude的正则表达式:
排除: /node_modules\,
必须使用正斜杠而不是反斜杠:
排除:/节点_模块/https://stackoverflow.com/questions/55166437
复制相似问题