首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >为什么npm为babel运行build抛出一个错误:"babel: src不存在“

为什么npm为babel运行build抛出一个错误:"babel: src不存在“
EN

Stack Overflow用户
提问于 2019-11-07 10:06:31
回答 1查看 1.3K关注 0票数 0

我的文件夹是src,我已经通过CLI安装了babel,但是我仍然收到一个错误,"babel: src不存在“

下面是我的代码的快速记录:https://drive.google.com/file/d/1YgEnJE87c0mEnsefY1xU94cvUedBtGhK/view

查看上面我尝试过的内容。

代码语言:javascript
运行
复制
{
  "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

代码语言:javascript
运行
复制
import getNotes from "notes.js"

getNotes()

notes.js

代码语言:javascript
运行
复制
let getNotes = function() {
    console.log(`Put the time in baby!`)
}

module.exports = getNotes

我期望babel在app.js中运行并编译我的ES6导入代码,但却在终端中收到以下错误:

代码语言:javascript
运行
复制
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
EN

回答 1

Stack Overflow用户

发布于 2019-11-08 03:24:59

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58740966

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档