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

Error: Got unexpected undefined #8375

Open
chin2km opened this issue Aug 8, 2022 · 22 comments
Open

Error: Got unexpected undefined #8375

chin2km opened this issue Aug 8, 2022 · 22 comments
Labels

Comments

@chin2km
Copy link

chin2km commented Aug 8, 2022

🐛 bug report

Trying to migrate a very large repository (private to a company) from webpack to parcel, I'm facing this frequent build error Error: Got unexpected undefined when running parcel watch and the error log doesn't say much more than that. After adding some manual error logging at the source in parcel core in node module I have some more info. Its getting thrown when running svg,jpg,png files through the compressors in this function in @pracel/core.

We loved parcel in our tests and plan to use parcel in dev mode as of now (with plan to use in production later), but this error blocks us. Tried several fixes suggestion from various issues in the repo already but none seems to fix this particular issue.

Any suggestions/help to get around this is highly appreciated.

example complete error

 console: >> errorrrr {
   filePath: 'packages/application-desktop/dist/assets/apple-app-store-badge_nl.8fed9113.svg',
   err: Error: Got unexpected undefined
       at nullthrows (/Users/chintu.mohandas/Documents/Company/frontend-web/node_modules/nullthrows/nullthrows.js:7:15)
       at Object.run (/Users/chintu.mohandas/Documents/Company/frontend-web/node_modules/@parcel/core/lib/requests/DevDepRequest.js:133:54)
       at RequestTracker.runRequest (/Users/chintu.mohandas/Documents/Company/frontend-web/node_modules/@parcel/core/lib/RequestTracker.js:725:34)
       at Object.runRequest (/Users/chintu.mohandas/Documents/Company/frontend-web/node_modules/@parcel/core/lib/RequestTracker.js:777:23)
       at runDevDepRequest (/Users/chintu.mohandas/Documents/Company/frontend-web/node_modules/@parcel/core/lib/requests/DevDepRequest.js:127:13)
       at runCompressor (/Users/chintu.mohandas/Documents/Company/frontend-web/node_modules/@parcel/core/lib/requests/WriteBundleRequest.js:240:47)
       at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
       at async Promise.all (index 0)
       at async writeFiles (/Users/chintu.mohandas/Documents/Company/frontend-web/node_modules/@parcel/core/lib/requests/WriteBundleRequest.js:207:3)
       at async Object.run (/Users/chintu.mohandas/Documents/Company/frontend-web/node_modules/@parcel/core/lib/requests/WriteBundleRequest.js:179:3) {
     framesToPop: 1
   },
   compressors: [
     {
       plugin: [Object],
       version: '2.7.0',
       resolveFrom: 'node_modules/@parcel/config-default/index.json',
       range: undefined,
       name: '@parcel/compressor-raw',
       keyPath: '/compressors/*/0'
     }
   ]
 }

The error happens when the svg,jpg,png files are run through @parcel/compressor-raw. Is there a way to skip using any compressor at all during dev mode?

.parcelrc

{
  "extends": [
    "@parcel/config-default"
  ],

  "resolveFrom": ".",
}

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

package.json

"scripts": {
    "client:dev": "parcel watch --target=client",
    "server:dev": "parcel watch --target=server",
    "develop:beta": "concurrently 'yarn client:dev' 'yarn server:dev'"
  },
  "targets": {
    "client": {
      "context": "browser",
      "source": "./src/index.html",
      "distDir": "./dist/assets",
      "publicUrl": "/assets/"
    },
    "server": {
      "context": "node",
      "outputFormat": "esmodule",
      "source": "./src/server-entry.tsx",
      "distDir": "./dist/server",
      "publicUrl": "/assets/",
      "includeNodeModules": false,
      "sourceMap": true
    }
  },

🤔 Expected Behavior

No errors in final compression stage

😯 Current Behavior

Described above

💁 Possible Solution

A Way to skip compressors for file globs?

🔦 Context

We are trying a build a very large server rendered react application with parcel.

💻 Code Sample

Happens in a private repo.

🌍 Your Environment

Software Version(s)
Parcel 2.7.0
Node 16.14.2
npm/Yarn yarn 1.22.19
Operating System macOS Mac M1 Pro
@sznowicki
Copy link

It seems it's happening only on ARM. We're debugging the same problem over here. Same codebase, works on Intel Mac, doesn't work on M1 Mac.

@sznowicki
Copy link

Our debugging so far showed that it's somewhat related to how parcel uses cache.

We have a massive file that exports around 1000 react components. When we comment all exports out, it works in a dev mode. Then if we uncomment group by group it still works. After uncommenting around 300 exports, it still works, then we stop the dev process, rm -rf .parcel-cache and again parcel throws that error OP posted.

It feels like there's some sort of overflow somewhere. Weird it's only on ARM though.

@chin2km
Copy link
Author

chin2km commented Aug 8, 2022

@sznowicki I can confirm most of that. This seems to happen only on M1 Mac. And ours is also a huge mono-repo with tons of JS and static assets file.

I also thought its mostly related to cache, but I run into the same issue even with --no-cache flag.

Already tried things like setting PARCEL_WORKER_BACKEND=process and PARCEL_WORKERS and various combination of .parcelrc but none seems to fix these issues.

@sznowicki
Copy link

From my observation "no-cache" makes it even worse. I suspect there's some weird memory problem. By "related to cache" I meant that if more is cached then problem disappears.

@sznowicki
Copy link

sznowicki commented Aug 9, 2022

Now I got the same errors on my Intel Mac.

What changed is only we updated a dependency which holds all our corporate icons. The file count grew from ~1200 files to > 2400.

It worked until I changed the version of this dependency from 1.0.0-dev.1 to 1.0.0. From now on I get those unexpected undefined too.

Eventually I got it working:

  1. start dev -> fail
  2. start again -> fail
  3. start again -> works
  4. remove .parcel-cache -> start again -> still works

ARM Mac fails consistently. It really feels like some odd race condition somewhere.

@chin2km
Copy link
Author

chin2km commented Aug 9, 2022

  1. start dev -> fail
  2. start again -> fail
  3. start again -> works
  4. remove .parcel-cache -> start again -> still works

same for me. But if you remove the dist folder in addition to .parcel-cache the fails starts over.
Overall in my tries I only had 10-20% success-rate when starting dev mode.

ARM Mac fails consistently

Same.

@andrewvmail
Copy link

I have a project that ran fine on an M1 mac 16GB and get this error on an M1 mac 8GB...

@sznowicki
Copy link

sznowicki commented Aug 16, 2022

We did some additional tests and it really seems like if you try enough times it eventually builds up enough cache to not expose this (probable) memory issue and start the dev process (with PARCEL_WORKER_BACKEND=process).

We just tried it on Intel and ARM Macs. After 5 - 6 times of starting parcel it finally took off.

@MSpiechowicz
Copy link

MSpiechowicz commented Aug 17, 2022

Within one project with a lot of files using this flag PARCEL_WORKER_BACKEND=process helps, but in the other which does not have this amount of files it does not help and the same issue appears.

I would say that this is a major bug related to the M1 architecture or some memory leak/optimization.

@eMerzh
Copy link

eMerzh commented Sep 4, 2022

hye, just shiming in, but i'm trying to upgrade some outdated repo to current version of parcel, and in the process i stumble upon this too...

i'm on mac intel, so it's not just arm....

also suspect memory/file count/size related... not much else to suggest atm ... still digging

@HcroakerDev
Copy link

Still getting this issue on parcel v2.8.0. Any idea on how to fix?

@mischnic
Copy link
Member

Please share a reproduction if you have a situation where this happens consistently. That would help with getting this fixed

@gorakong
Copy link
Member

possible fix: #6644

@chin2km
Copy link
Author

chin2km commented Jan 16, 2023

possible fix: #6644

looking forward to this fix 🎉

@ppqn
Copy link

ppqn commented Mar 19, 2023

For me, it's the two for loops starting here:

https://github.com/parcel-bundler/parcel/blob/v2/packages/core/core/src/requests/DevDepRequest.js#L187

image

the devDepRequest object sometimes doesn't have invalidateOnFileChange and/or invalidateOnFileCreate and thus it throws that undefined error.

I just put an if block around each for those loops making sure the desired value exist and my code compiles fine.

@arty-name
Copy link
Contributor

@mischnic Here’s a reproduction case for the error on the public repository. The issue only started appearing with the upgrade to 2.9.0 though.

@calebsakala
Copy link

I got (and FIXED) an extremely similar error ("Parcel build error got unexpected null") when I accidentally added ES6 syntax to a JavaScript file that had CommonJS syntax elsewhere. I added some ES6 "export" statements, when elsewhere in the file, my code was using a require(). I found which file was problematic by relocating all the files I suspected to a faraway folder, and then retrying the build. If the build worked, then I knew that all the remaining files were okay.

I added in the suspect files one by one, building after each add. When the build threw an error, I examined the newly added file and commented out all of its code - and then I built again (just to see if the build would work). I slowly uncommented the code until an error was triggered. By this process, I narrowed it down to two HTML files -> two modules -> two imports -> one import -> one file -> a couple of lines within the file and once I realised that I was mixing ES6 with commonJS, I fixed it and it worked just fine again. There isn't really a lot about this error online but I hope that if somebody sees this, it'll help them fix their error too.

@lukeg90
Copy link

lukeg90 commented Oct 12, 2023

Still getting this error on 2.10.0

@github-actions github-actions bot added the Stale Inactive issues label Apr 10, 2024
@arty-name
Copy link
Contributor

Still getting this error on v2.12.0

@github-actions github-actions bot removed the Stale Inactive issues label Apr 10, 2024
@calebsakala
Copy link

calebsakala commented Apr 10, 2024 via email

@arty-name
Copy link
Contributor

While it could help in some codebases, it’s not the case in 3 of mine projects, so a cleanup is not a solution :(

@mcurros2
Copy link

Just adding my two cents here.

In my case the problem was hit in a library that re-exports folders. Ie. ComponentGroup/component/componentItems.

If some component in components items imports everything from /ComponentGroup you may hit this. Maybe, because at some point it can't determine the correct order for dependencies.

Fixed that importing each dependency from their correct folder: from ComponentGroup, ComponentGroup/component instead everything from ComponentGroup.

@github-actions github-actions bot removed the Stale Inactive issues label Oct 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests