我的文件夹是src,我已经通过CLI安装了babel,但是我仍然收到一个错误,"babel: src不存在“
下面是我的代码的快速记录:https://drive.google.com/file/d/1YgEnJE87c0mEnsefY1xU94cvUedBtGhK/view
查看上面我尝试过的内容。
{
"name": "notes-app",
"version": "1.0.0",
"description": "",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "babel src -d lib"
},
"author": "Jono Suave",
"license": "ISC",
"devDependencies": {
"@babel/cli": "^7.7.0",
"@babel/core": "^7.7.2"
}
}
app.js
import getNotes from "notes.js"
getNotes()
notes.js
let getNotes = function() {
console.log(`Put the time in baby!`)
}
module.exports = getNotes
我期望babel在app.js中运行并编译我的ES6导入代码,但却在终端中收到以下错误:
babel:
src does not exist
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! notes-app@1.0.0 build: `babel src -d lib`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the notes-app@1.0.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/jonosuave/.npm/_logs/2019-11-07T01_56_26_260Z-debug.log
发布于 2019-11-07 19:24:59
在实验节点中,甚至不需要Babel --只需要对文件使用.mjs扩展名,而不是.js参见示例:How can I use an es6 import in node?的解释
https://stackoverflow.com/questions/58740966
复制相似问题