【发布时间】:2020-03-03 13:48:54
【问题描述】:
我的文件夹是 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
【问题讨论】:
-
你有你的
package.jsoninside 的src吗?通常他们是兄弟姐妹。 -
谢谢你,成功了!但是,现在我收到一个错误: import { getNotes } from './notes'; ^^^^^^ @loganfsmyth SyntaxError: Cannot use import statement outside a module 这是屏幕录制链接:drive.google.com/file/d/1lMv59tak_qrMNSNwU7_Cahr7yNuMsn5S/view