mmohammad
mmohammad

Reputation: 2812

Cannot find module '@babel/parser'

I am no longer able to transpile my codebase when running babel. I made. It wasn't happening before and I am unable to figure out why. This only happened when I pulled remote master branch, which had yarn.lock conflicts. I resolved conflicts with the yarn commands.

here is part of my package.json

{
  "devDependencies": {
    "@babel/cli": "^7.1.0",
    "@babel/core": "^7.1.2",
    "@babel/plugin-proposal-class-properties": "^7.0.0",
    "@babel/plugin-proposal-decorators": "^7.0.0",
    "@babel/plugin-proposal-export-default-from": "^7.0.0",
    "@babel/plugin-proposal-export-namespace-from": "^7.0.0",
    "@babel/plugin-proposal-function-sent": "^7.0.0",
    "@babel/plugin-transform-runtime": "^7.1.0",
    "@babel/polyfill": "^7.0.0",
    "@babel/preset-env": "^7.1.0",
    "@babel/preset-react": "^7.0.0",
    "@babel/register": "^7.0.0",
    ...
  }
}

Running babel src -d build results in the following error

{ Error: Cannot find module '@babel/parser'
    at Function.Module._resolveFilename (module.js:548:15)
    at Function.Module._load (module.js:475:25)
    at Module.require (module.js:597:17)
    at require (internal/module.js:11:18)
    at _parser (/Users/mohammadmohammad/Dev/work/procore/hydra_clients/budgetViewer/node_modules/@babel/core/lib/transformation/normalize-file.js:59:16)
    at parser (/Users/mohammadmohammad/Dev/work/procore/hydra_clients/budgetViewer/node_modules/@babel/core/lib/transformation/normalize-file.js:170:18)
    at normalizeFile (/Users/mohammadmohammad/Dev/work/procore/hydra_clients/budgetViewer/node_modules/@babel/core/lib/transformation/normalize-file.js:138:11)
    at runSync (/Users/mohammadmohammad/Dev/work/procore/hydra_clients/budgetViewer/node_modules/@babel/core/lib/transformation/index.js:44:43)
    at runAsync (/Users/mohammadmohammad/Dev/work/procore/hydra_clients/budgetViewer/node_modules/@babel/core/lib/transformation/index.js:35:14)
    at /Users/mohammadmohammad/Dev/work/procore/hydra_clients/budgetViewer/node_modules/@babel/core/lib/transform-file.js:58:36 code: 'MODULE_NOT_FOUND' }

I also tried deleting node_modules and run yarn install with no luck.

Upvotes: 7

Views: 22570

Answers (4)

Liran H
Liran H

Reputation: 10609

For me the solution was to delete the node_modules folder, and reinstall

rm -rf node_modules
yarn

Upvotes: 12

ProgIn
ProgIn

Reputation: 351

Below command worked for me

npm audit fix --force

Please note that audit fix install SemVer-major updates to toplevel dependencies, not just SemVer-compatible ones (https://docs.npmjs.com/cli/v7/commands/npm-audit)

Upvotes: 0

Aakash
Aakash

Reputation: 23795

This is what worked for me:

yarn add -D @babel/parser

OR with NPM

npm i -D @babel/parser

Good Luck...

Upvotes: 4

mmohammad
mmohammad

Reputation: 2812

Was able to resolve the issue by simply bumping babel-eslint from 8.2,3 to 10.0.1

Upvotes: 9

Related Questions