Cannot find module 'babel-node'

945 Views Asked by At

I am trying to run some React code on my server-side using node. Following a tutorial, I am trying to add babel to my node server so that JSX gets transpiled to JS.

I added the run scripts to my json.config to use babel-node as below (I use the "watch-server" script for development):

"scripts": {
"start": "start:dev",
"server": "node babel-node ./server/index.js",
"start:dev": "webpack && npm run server",
"start:prod": "webpack && npm run server",
"test": "jest",
"test:debug": "jest --debug",
"test:watch": "jest --watch",
"test:coverage": "jest --coverage --colors",
"watch-server": "nodemon -e js,scss,jsx --ignore '*.bundle*.js' --verbose --exec npm run start:dev"

The issue I get is when I try to run npm run watch-server is an error:

> node babel-node ./server/index.js

internal/modules/cjs/loader.js:905
  throw err;
  ^

Error: Cannot find module '/Users/zarnowm/Documents/GitHub/dsr-ux/babel-node'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:902:15)
    at Function.Module._load (internal/modules/cjs/loader.js:746:27)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12)
    at internal/main/run_main_module.js:17:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}

Here is a snippet of my dependencies:

"devDependencies": {
    "@babel/core": "^7.4.3",
    "@babel/node": "^7.14.9",
    "@babel/plugin-proposal-class-properties": "^7.4.0",
    "@babel/plugin-proposal-object-rest-spread": "^7.4.3",
    "@babel/plugin-transform-runtime": "^7.4.3",
    "@babel/preset-env": "^7.4.3",
    "@babel/preset-react": "^7.0.0",
    "@babel/runtime": "^7.5.0",

And .babelrc:

{
  "env": {
    "test": {
      "presets": [
        "@babel/preset-env",
        "@babel/preset-react"
      ],
      "plugins": [
        "@babel/plugin-proposal-class-properties",
        "@babel/plugin-proposal-object-rest-spread",
        "@babel/plugin-transform-runtime"
      ]
    }
  }
}

Im struggling to figure out the issue...

0

There are 0 best solutions below