Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parcel serve: Got unexpected null #6043

Closed
danieltroger opened this issue Mar 23, 2021 · 20 comments · Fixed by #6067
Closed

Parcel serve: Got unexpected null #6043

danieltroger opened this issue Mar 23, 2021 · 20 comments · Fixed by #6067

Comments

@danieltroger
Copy link
Contributor

🐛 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)
@danieltroger
Copy link
Contributor Author

It just happened again

ℹ️ Server running at http://localhost:1234
✨ Built in 3.60s
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
}
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
}
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
}
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
}
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
}
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

@danieltroger
Copy link
Contributor Author

Can't reproduce with a simple script, so it seems to only happen when using certain features.

It also happens in 2.0.0-nightly.629+39ff8330

@mischnic
Copy link
Member

That code was recently changed, can you provide a complete code sample?

@danieltroger
Copy link
Contributor Author

Btw, my .parcelrc:

{
	"extends": "@parcel/config-default",
	"optimizers": {
	    "bundle-text:*.css": ["@parcel/optimizer-cssnano"],
		  "bundle-text:*.html": ["@parcel/optimizer-htmlnano"]
	},
	"transformers": {
    "bundle-text:*.html": ["@parcel/transformer-inline-string"]
  }
}

@danieltroger
Copy link
Contributor Author

That code was recently changed, can you provide a complete code sample?

It's kind of hard because my work isn't open source and it doesn't happen with everything. But I'll try to hack something together in hopes of triggering it :)

@danieltroger
Copy link
Contributor Author

danieltroger commented Mar 23, 2021

No luck in triggering it outside of my environment so far, but I printed the thing which doesn't have a filePath to console and it looks like this and seems to have something to do with css compression:

console: {
  id: '075c5f501f5241fc128d21da8d4878ed',
  hashReference: 'HASH_REF_075c5f501f5241fc128d21da8d4878ed',
  type: 'css',
  env: {
    id: '28bfbdbbbe851c4cbd6803ebbb8ba7c3',
    context: 'browser',
    engines: { browsers: 'last 1 firefox version' },
    includeNodeModules: true,
    outputFormat: 'global',
    isLibrary: false,
    shouldOptimize: false,
    shouldScopeHoist: false,
    sourceMap: {}
  },
  entryAssetIds: [ '2fbd23f723195c66e2096d4734e1622e' ],
  mainEntryId: '2fbd23f723195c66e2096d4734e1622e',
  pipeline: 'bundle-text',
  filePath: null,
  isEntry: false,
  isInline: true,
  isSplittable: true,
  isPlaceholder: false,
  target: {
    name: 'dev',
    distDir: '[project_dir]/dev_dist/directory',
    distEntry: 'output_filename.js',
    publicUrl: '/',
    env: {
      id: '28bfbdbbbe851c4cbd6803ebbb8ba7c3',
      context: 'browser',
      engines: [Object],
      includeNodeModules: true,
      outputFormat: 'global',
      isLibrary: false,
      shouldOptimize: false,
      shouldScopeHoist: false,
      sourceMap: {}
    },
    loc: {
      filePath: '[project_dir]/package.json',
      start: [Object],
      end: [Object]
    }
  },
  name: 'output_filename.HASH_REF_075c5f501f5241fc128d21da8d4878ed.css',
  displayName: 'output_filename.[hash].css',
  publicId: 'dT9Xa',
  stats: { size: 1547, time: 0 }
}

I have done this in node_modules/@parcel/core/lib/public/Bundle.js

get filePath() {
    console.log(_classPrivateFieldGet(this, _bundle3));
    return (0, _nullthrows().default)(_classPrivateFieldGet(this, _bundle3).filePath);
  }

@danieltroger
Copy link
Contributor Author

Put this into styling.css:

body {
  background: red;
}

and this into main.ts

// @ts-ignore
import styling from "bundle-text:./styling.css";

console.log(styling);

I got that to crash once but after that never again. Maybe it crashes for you too the first time which would satisfy being a reproduction :)

@mischnic mischnic changed the title Parcel serve breaks when getting a request Parcel serve: Got unexpected null Mar 24, 2021
@mischnic
Copy link
Member

mischnic commented Mar 24, 2021

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 ...

@danieltroger
Copy link
Contributor Author

Great that you could reproduce! But I'm only using bundle-text and still get the error. Maybe the filePath is lost somewhere during processing?

@mischnic
Copy link
Member

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:

@ittaibaratz
Copy link
Contributor

We are seeing that issue too I believe:

Error: Got unexpected null
     at nullthrows (/Users/leclair/dev/unified-shell/node_modules/nullthrows/nullthrows.js:7:15)
     at PackagedBundle.get filePath [as filePath] (/Users/leclair/dev/unified-shell/node_modules/@parcel/core/lib/public/Bundle.js:367:38)
     at /Users/leclair/dev/unified-shell/node_modules/@parcel/reporter-dev-server/lib/Server.js:272:104
     at Array.find (<anonymous>)
     at Server.serveBundle (/Users/leclair/dev/unified-shell/node_modules/@parcel/reporter-dev-server/lib/Server.js:272:45)
     at Server.respond (/Users/leclair/dev/unified-shell/node_modules/@parcel/reporter-dev-server/lib/Server.js:219:19)
     at /Users/leclair/dev/unified-shell/node_modules/@parcel/reporter-dev-server/lib/Server.js:441:14
     at call (/Users/leclair/dev/unified-shell/node_modules/@parcel/reporter-dev-server/node_modules/connect/index.js:239:7)
     at next (/Users/leclair/dev/unified-shell/node_modules/@parcel/reporter-dev-server/node_modules/connect/index.js:183:5)
     at Function.handle (/Users/leclair/dev/unified-shell/node_modules/@parcel/reporter-dev-server/node_modules/connect/index.js:186:3) {
   framesToPop: 1
 }

@danmarshall
Copy link
Contributor

I got this error when I had accidentally overwritten my import with parcel output, which made it no longer a module.

@3A43Mka
Copy link

3A43Mka commented Dec 6, 2022

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

@gxy5202
Copy link

gxy5202 commented Feb 1, 2023

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

me too. after deleting cache folder, all gose well

@darklordofgnar
Copy link

thanks for your help on this, deleting the .parcel-cache folder cleared any issues for me as well

@Aneeshaik
Copy link

thank you so much for help, I am trying to fix this from yesterday now it also worked for me after deleting .parcel-cache

@KaushikJallam
Copy link

KaushikJallam commented Jun 16, 2024

Deleting the parcel-cache will work

@fatdarkness6
Copy link

Deleting the parcel-cache will work

thanks a lot . it worked for me after deleting parcel-cache

@AmanKumar-09
Copy link

I have getting this error how can I solve this error please help 🙏🏿
PS C:\Users\Aman\OneDrive\Desktop\Namaste-React\Food-App> npm start

food-app@1.0.0 start
parcel index.html

Error: Got unexpected null
at nullthrows (C:\Users\Aman\OneDrive\Desktop\Namaste-React\Food-App\node_modules\nullthrows\nullthrows.js:7:15)
at RequestGraph.invalidateOptionNodes (C:\Users\Aman\OneDrive\Desktop\Namaste-React\Food-App\node_modules@parcel\core\lib\RequestTracker.js:248:44)
at loadRequestGraph (C:\Users\Aman\OneDrive\Desktop\Namaste-React\Food-App\node_modules@parcel\core\lib\RequestTracker.js:872:18)
at async RequestTracker.init (C:\Users\Aman\OneDrive\Desktop\Namaste-React\Food-App\node_modules@parcel\core\lib\RequestTracker.js:822:17)
at async Parcel._init (C:\Users\Aman\OneDrive\Desktop\Namaste-React\Food-App\node_modules@parcel\core\lib\Parcel.js:188:28)
at async Parcel.watch (C:\Users\Aman\OneDrive\Desktop\Namaste-React\Food-App\node_modules@parcel\core\lib\Parcel.js:260:7)
at async run (C:\Users\Aman\OneDrive\Desktop\Namaste-React\Food-App\node_modules\parcel\lib\cli.js:283:9) {
framesToPop: 1
}

@mohanbawane
Copy link

I have getting this error how can I solve this error please give me the solution

Error: Got unexpected undefined
at nullthrows (C:\Users\Mohan Bawane\OneDrive\Desktop\685678\Own namaste\node_modules\nullthrows\nullthrows.js:7:15)
at RequestGraph.invalidateOptionNodes (C:\Users\Mohan Bawane\OneDrive\Desktop\685678\Own namaste\node_modules@parcel\core\lib\RequestTracker.js:248:44)
at loadRequestGraph (C:\Users\Mohan Bawane\OneDrive\Desktop\685678\Own namaste\node_modules@parcel\core\lib\RequestTracker.js:872:18)
at async RequestTracker.init (C:\Users\Mohan Bawane\OneDrive\Desktop\685678\Own namaste\node_modules@parcel\core\lib\RequestTracker.js:822:17)
at async Parcel._init (C:\Users\Mohan Bawane\OneDrive\Desktop\685678\Own namaste\node_modules@parcel\core\lib\Parcel.js:188:28)
at async Parcel.watch (C:\Users\Mohan Bawane\OneDrive\Desktop\685678\Own namaste\node_modules@parcel\core\lib\Parcel.js:260:7)
at async run (C:\Users\Mohan Bawane\OneDrive\Desktop\685678\Own namaste\node_modules\parcel\lib\cli.js:283:9) {
framesToPop: 1
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.