0

EDIT: Answered, below.

Also: If you are reading this you are probably new to web dev and you should consider using webpack for this instead of babel alone

I have what seems like a very simple problem but I can't solve it.

I have a directory structure

Project
 |
 +-- scripts
    |
    |
    +-- src / src.js
    |
    |
    +-- compiled / compiled.js

And I have been trying to get the following command to work when my terminal is located in the scripts folder.

C:\Users\me\JavaScriptProjects\survey\scripts>npx babel ./src/src.js --out-file ./compiled/compiled.js presets=env,react --watch

But it simply keeps returning:

C:\Users\me\JavaScriptProjects\survey\scripts>npx babel ./src/src.js --out-file ./compiled/compiled.js presets=env,react --watch presets=env,react doesn't exist

I have tried permutations of removing the ./, replacing it with only /, going into src dir and replacing src/src.js with src.js and then doing ../compiled/compiled.js and many other permutations, but it just keeps saying it doesn't exist.

Even if I add both files to the same directory it's giving the same error.

Most annoying part is it was working fine yesterday.

Thanks in advance.

Paul Wilson
  • 562
  • 5
  • 16

2 Answers2

0

Solved.

The following has worked from within the src dir after trying for around an hour. I don't know what I've done differently, would love it if someone can point it out.

Thanks.

C:\Users\me\JavaScriptProjects\survey\scripts\src>npx babel src.js --out-file=../compiled/compiled.js --presets=env,react --watch
Paul Wilson
  • 562
  • 5
  • 16
0

It could be that you have a babel.config.json file in the \scripts\src folder and that if you move to the \scripts folder to run npx, then it can't see the config file and so doesn't see react.

Project
 |
 +-- scripts
    |
    +-- src / src.js
    +-- src / babel.config.json
    |
    +-- compiled / compiled.js
jaesle
  • 548
  • 4
  • 14