parcel: Parcel serve: Got unexpected null

🐛 bug report

I’ve been getting this error when running parcel serve a couple times today

ℹ️ Server running at http://localhost:1234
✨ Built in 3.71s
Error: Got unexpected null
    at nullthrows ([project_dir]node_modules/nullthrows/nullthrows.js:7:15)
    at PackagedBundle.get filePath [as filePath] ([project_dir]node_modules/@parcel/core/lib/public/Bundle.js:367:38)
    at [project_dir]node_modules/@parcel/reporter-dev-server/lib/Server.js:272:104
    at Array.find (<anonymous>)
    at Server.serveBundle ([project_dir]node_modules/@parcel/reporter-dev-server/lib/Server.js:272:45)
    at Server.respond ([project_dir]node_modules/@parcel/reporter-dev-server/lib/Server.js:219:19)
    at [project_dir]node_modules/@parcel/reporter-dev-server/lib/Server.js:440:14
    at call ([project_dir]node_modules/connect/index.js:239:7)
    at next ([project_dir]node_modules/connect/index.js:183:5)
    at Function.handle ([project_dir]node_modules/connect/index.js:186:3) {
  framesToPop: 1
}
npm ERR! code 1
npm ERR! path [project_dir]
npm ERR! command failed
npm ERR! command sh -c ./build_scripts/serve

I’ve tried cleaning the cache and it didn’t help. It happens after like the 2nd or 3rd request.

Unfortunately when I tried to actively reproduce it it stopped and has been working since 😦 I’ll update with more info if it happens again. I have a new laptop so maybe something’s not set up correctly.

🎛 Configuration (.babelrc, package.json, cli command)

package.json

{
  "scripts": {
    "serve": "dotenv -e .env.development -- parcel serve --port 1234 --target dev --no-cache --no-hmr --dist-dir dev_dist/myscript src/main.ts",
  },
  "targets": {
    "dev": {
      "engines": {
        "browsers": "last 1 firefox version"
      }
    }
  },
  "devDependencies": {
    "@babel/cli": "latest",
    "@babel/core": "latest",
    "@babel/plugin-proposal-class-properties": "latest",
    "@babel/plugin-proposal-private-methods": "latest",
    "@babel/preset-typescript": "latest",
    "@parcel/babel-plugin-transform-runtime": "nightly",
    "@parcel/babel-preset-env": "nightly",
    "@parcel/optimizer-cssnano": "nightly",
    "@parcel/optimizer-htmlnano": "nightly",
    "@parcel/packager-css": "nightly",
    "@parcel/packager-html": "nightly",
    "@parcel/transformer-css": "nightly",
    "@parcel/transformer-html": "nightly",
    "@parcel/transformer-inline-string": "nightly",
    "@parcel/transformer-postcss": "nightly",
    "@parcel/transformer-posthtml": "nightly",
    "parcel": "nightly",
    "segfault-handler": "latest",
    "terser": "latest"
  },
  "dependencies": {
    "@babel/runtime": "latest",
    "@babel/runtime-corejs3": "latest",
    "dotenv-cli": "latest"
  }
}

.babelrc:

{
  "presets": ["@babel/preset-typescript", "@parcel/babel-preset-env"],
  "plugins": ["@parcel/babel-plugin-transform-runtime"]
}

🤔 Expected Behavior

Parcel serve should not crash.

😯 Current Behavior

It crashes sometimes.

💁 Possible Solution

Never crash.

🔦 Context

Wanted to continue developing my script and wondered why nothing happened.

💻 Code Sample

I’ll post one if I manage to reproduce it with something that’s not my whole code

🌍 Your Environment

Software Version(s)
Parcel 2.0.0-nightly.630+ed726670
Node v15.12.0
npm 7.6.3
Operating System macOS Catalina 10.15.7 (19H15)

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 15 (12 by maintainers)

Most upvoted comments

In my case, I had to delete .parcel-cache folder, after that it worked without any issues.

It’s intentional that inline bundles don’t have a file path, as they are never written to disk directly (and namer plugins aren’t invoked for them).

So the fix would be adding .filter(b => !b.isInline) here: https://github.com/parcel-bundler/parcel/blob/dea272f0708fdabfe11f844f189df6421e7a3b65/packages/reporters/dev-server/src/Server.js#L209

I just got this error as well, looks like it was caused by an inline CSS bundle that was created because of <style></style> tags.

Inline bundles do indeed not have a filepath …