Cannot find module 'json5' on initial run

See original GitHub issue

πŸ› bug report

On a brand new project, running either one of the following commands would result in the error (see Current Behavior section) from the command line

parcel ./src/index.html
npm run dev

πŸŽ› Configuration (.babelrc, package.json, cli command)

package.json

{
  "name": "dummy-project",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "scripts": {
    "dev": "parcel ./src/index.html",
    "build": "parcel build ./src/index.html/"
  },
  "dependencies": {
    "react": "^16.6.3",
    "react-dom": "^16.6.3"
  },
  "devDependencies": {
    "babel-core": "^6.26.3",
    "babel-preset-env": "^1.7.0",
    "babel-preset-react": "^6.24.1",
    "parcel-bundler": "^1.10.3"
  }
}

.babelrc

{
  "presets": [
    "env",
    "react"
  ]
}

src/index.js

console.log('ready')

src/index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <div id="root"></div>
    <script src="./index.js"></script>
</body>
</html>
{
  "your": { "config": "here" }
}

πŸ€” Expected Behavior

Parcel should compile without issues.

😯 Current Behavior

The initial run would give the following error. However if I ^C and re-run the command it compiles without issues.

Error:

Cannot find module β€˜json5’

/path-to/dummy-project/src/index.js: Cannot find module 'json5'
    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 (/path-to/dummy-project/node_modules/v8-compile-cache/v8-compile-cache.js:159:20)
    at Object.<anonymous> (/path-to/dummy-project/node_modules/babel-core/lib/transformation/file/options/build-config-chain.js:19:13)
    at Module._compile (/path-to/dummy-project/node_modules/v8-compile-cache/v8-compile-cache.js:178:30)
    at Object.Module._extensions..js (module.js:664:10)
    at Module.load (module.js:566:32)
    at tryModuleLoad (module.js:506:12)
    at Function.Module._load (module.js:498:3)

πŸ’ Possible Solution

As a workaround for now, I simply ^C and re-run the command. And it’ll be fine after that.

πŸ”¦ Context

I am using the following repo that I came up with a few days ago to scaffold the project:

https://github.com/midnightcodr/create-with-parcel

πŸ’» Code Sample

🌍 Your Environment

Software Version(s)
Parcel 1.10.3
Node v8.12.0
npm/Yarn 6.4.1 / 1.12.3
Operating System Mac Mojave 10.14.1

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:7
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
george-haddadcommented, Jan 25, 2019

OK fixed my issue I had to update "babel-loader": "^8.0.4" to "babel-loader": "^8.0.5" so @midnightcodr why don’t you try to add babel-loader@8.0.5 to your project and try again.

1reaction
midnightcodrcommented, Mar 7, 2019

Just discovered a solution to the problem I have. All I have to do is to install json5 explicitly before I do npm run dev. See https://github.com/midnightcodr/create-with-parcel/commit/9fc45caafd4118b1c0e1a02d0b1074b4dfad4519 for details

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I resolve "Cannot find module" error using Node.js?
Using npm install installs the module into the current directory only (in a subdirectory called node_modules ). Is app.js located underΒ ...
Read more >
json5 - npm
Start using json5 in your project by running `npm i json5`. There are 3330 other projects in the npm registry using json5.
Read more >
json5 | Yarn - Package Manager
JSON5 is an extension to the popular JSON file format that aims to be easier to write and maintain by hand (e.g. for...
Read more >
json5 - PyPI
A Python implementation of the JSON5 data format. ... pip install json5 ... There are a few other more minor extensions to JSON;...
Read more >
JSON5 – JSON for Humans | JSON5
JSON5 is an extension to the popular JSON file format that aims to be easier to write and maintain by hand (e.g. for...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found