【问题标题】:Why does npm run build for babel throw an error: "babel: src does not exist"为什么 npm run build for babel 会抛出错误:“babel: src 不存在”
【发布时间】: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

【问题讨论】:

标签: node.js babeljs


【解决方案1】:

在实验节点中,甚至不需要 Babel —— 只需要对文件使用 .mjs 扩展名而不是 .js 请参阅示例说明:How can I use an es6 import in node?

【讨论】:

    猜你喜欢
    • 2020-09-20
    • 2017-11-18
    • 1970-01-01
    • 1970-01-01
    • 2018-11-19
    • 1970-01-01
    • 2019-07-07
    • 2016-09-09
    • 2021-03-03
    相关资源
    最近更新 更多