0

My folder is src and I've installed babel via the CLI, yet I'm still getting an error, "babel: src does not exist"

Here's a quick recording of of my code: https://drive.google.com/file/d/1YgEnJE87c0mEnsefY1xU94cvUedBtGhK/view

See above what I've tried.

{
  "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

I expected babel to run and compile my ES6 import code in app.js, but instead received following error in terminal:

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
Jono Suave
  • 101
  • 1
  • 5
  • 1
    Do you have your `package.json` _inside_ of `src`? Normally they would be siblings. – loganfsmyth Nov 07 '19 at 04:12
  • Thank you, that did the trick! However, now I'm getting an error: import { getNotes } from './notes'; ^^^^^^ @loganfsmyth SyntaxError: Cannot use import statement outside a module Here's a screen recording link: https://drive.google.com/file/d/1lMv59tak_qrMNSNwU7_Cahr7yNuMsn5S/view – Jono Suave Nov 07 '19 at 18:15
  • Figured it out: https://stackoverflow.com/questions/45854169/how-can-i-use-an-es6-import-in-node/50641589#50641589 – Jono Suave Nov 07 '19 at 19:23

1 Answers1

0

In experimental node, Babel isn't even required -- just need to use a .mjs extension to files instead of .js See explanation with example: How can I use an es6 import in node?

Jono Suave
  • 101
  • 1
  • 5