Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

npm start script with babel-node and dotenv

I have this script which works well

"start": "nodemon -x node -r dotenv/config src/index.js"

I want use babel-node instead node. So there is the new script:

"start": "nodemon -x babel-node --presets=env -r dotenv/config -- src/index.js"

But I get this error

[nodemon] starting `babel-node --presets=env -r dotenv/config src/index.js`
internal/modules/cjs/loader.js:583
    throw err;
    ^

Error: Cannot find module 'pathTo/dotenv/config'

Can you help ?

like image 241
doums Avatar asked Mar 27 '26 16:03

doums


2 Answers

This worked for me

    "start": "nodemon --exec babel-node -r node_modules/dotenv/config index.js"
like image 183
Aamir Mahmood Avatar answered Mar 30 '26 08:03

Aamir Mahmood


This issues existed for a short time in babel. @babel/node cannot seem to resolve node modules, when using --require flag

  "start": "nodemon --exec babel-node -r ./node_modules/dotenv/config src/index.js"

This issue has now been resolved. Allow -r from node_modules with @babel/node

  "start": "nodemon --exec babel-node -r dotenv/config src/index.js"
like image 30
Ali Motallebi Avatar answered Mar 30 '26 08:03

Ali Motallebi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!