kmagiera / babel-watch

Reload your babel-node app on JS source file changes. And do it fast.
MIT License
529 stars 70 forks source link

Error: Cannot find module '@babel/core' (Installing it didn't do anything) #113

Closed dsomel21 closed 3 years ago

dsomel21 commented 4 years ago

I have been trying to get babel-watch to work because babel-node doesn't reload for me... Here is my package.json:

{
  "name": "apollo-tut",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "build": "babel-watch server.js"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "express": "^4.17.1"
  },
  "devDependencies": {
    "babel-cli": "^6.26.0",
    "babel-preset-env": "^1.7.0",
    "babel-watch": "^7.0.0"
  }
}

But when I run npm run build I get:

> apollo-tut@1.0.0 build /Users/dilraj/Documents/JavaScript/Graphql/apollo-tut
> babel-watch server.js

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

Error: Cannot find module '@babel/core'
Require stack:
- /Users/dilraj/Documents/JavaScript/Graphql/apollo-tut/node_modules/babel-watch/babel-watch.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:961:17)
    at Function.Module._load (internal/modules/cjs/loader.js:854:27)
    at Module.require (internal/modules/cjs/loader.js:1023:19)
    at require (internal/modules/cjs/helpers.js:72:18)
    at Object.<anonymous> (/Users/dilraj/Documents/JavaScript/Graphql/apollo-tut/node_modules/babel-watch/babel-watch.js:7:15)
    at Module._compile (internal/modules/cjs/loader.js:1128:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1167:10)
    at Module.load (internal/modules/cjs/loader.js:983:32)
    at Function.Module._load (internal/modules/cjs/loader.js:891:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/Users/dilraj/Documents/JavaScript/Graphql/apollo-tut/node_modules/babel-watch/babel-watch.js'
  ]
}

When I install @babel/core using npm install --save-dev @babel/core ANDnpm install --save-dev babel-core I was getting a different error.

Babel compilation error TypeError: /Users/dilraj/Documents/JavaScript/Graphql/apollo-tut/server.js: Cannot read property 'bindings' of null
    at Scope.moveBindingTo (/Users/dilraj/Documents/JavaScript/Graphql/apollo-tut/node_modules/@babel/traverse/lib/scope/index.js:925:13)
STRML commented 3 years ago

I'm guessing here because I can't reproduce it, but I think the issue has to do with the fact that you have babel-core@6 installed. Babel doesn't play nice with multiple versions being installed.