请不要将此标记为任何Babel 6 问题的副本,因为这特别是关于Babel 7 ! < / p>
我正在尝试新的Babel 7测试版(@babel/polyfill@7.0.0-beta.32
等)并且我在使用@babel/polyfill
时遇到了麻烦。
我可能只是忘记了一些简单的事情,但我不能为我的生活弄清楚什么。任何想法是什么问题?
module.exports = {
presets: [
['@babel/preset-env', { targets: { node: 6 } }],
['@babel/preset-stage-3'],
['@babel/preset-flow']
]
}
require('@babel/polyfill')
module.exports = require('./main')
import 'dotenv-safe/config'
$ node --trace-warnings ./src/index.js
import 'dotenv-safe/config'
^^^^^^
SyntaxError: Unexpected token import
at createScript (vm.js:80:10)
at Object.runInThisContext (vm.js:139:10)
at Module._compile (module.js:599:28)
at Object.Module._extensions..js (module.js:646:10)
at Module.load (module.js:554:32)
at tryModuleLoad (module.js:497:12)
at Function.Module._load (module.js:489:3)
at Module.require (module.js:579:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/Users/deniz/Code/my-project/src/index.js:3:18)
{
"name": "foobar",
"private": true,
"version": "1.0.0",
"description": "lol",
"main": "./dist/bundle.js",
"module": "./src/main.js",
"scripts": {
"clean": "rimraf dist",
"build": "webpack",
"watch": "webpack -w",
"flow": "flow",
"flow-typed": "flow-typed",
"dev": "node --trace-warnings ./src/index.js",
"start": "node ./dist/bundle.js"
},
"devDependencies": {
"@babel/cli": "^7.0.0-beta.32",
"@babel/core": "^7.0.0-beta.32",
"@babel/preset-env": "^7.0.0-beta.32",
"@babel/preset-flow": "^7.0.0-beta.32",
"@babel/preset-stage-3": "^7.0.0-beta.32",
"babel-eslint": "^8.0.2",
"babel-loader": "^8.0.0-beta.0",
"dotenv-safe": "^4.0.4",
"eslint": "^4.12.0",
"eslint-config-prettier": "^2.9.0",
"eslint-plugin-flowtype": "^2.39.1",
"eslint-plugin-prettier": "^2.3.1",
"flow-bin": "^0.59.0",
"flow-typed": "^2.2.3",
"prettier": "^1.8.2",
"rimraf": "^2.6.2",
"webpack": "^3.9.1"
},
"dependencies": {
"@babel/polyfill": "^7.0.0-beta.32",
"node-schedule": "^1.2.5"
}
}
const path = require('path')
module.exports = {
target: 'node',
entry: ['./src/index.js'],
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'bundle.js'
},
module: {
rules: [
{
test: /\.js$/,
include: [path.resolve(__dirname, 'src')],
loader: 'babel-loader'
}
]
},
externals: [
{
mariasql: true,
msnodesql: true,
msnodesqlv8: true,
mysql: true,
mysql2: true,
oracle: true,
oracledb: true,
'pg-query-stream': true,
pg: true,
sqlite3: true,
'strong-oracle': true,
tds: true
}
],
devtool: 'source-map'
}
答案 0 :(得分:1)
尝试将入口点entry
更改为:entry: ['babel-polyfill', './src/index.js']
。根据文档,polyfill必须位于入口点的顶部。
https://babeljs.io/docs/usage/polyfill