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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncaught TypeError: Object.defineProperty called on non-object, caused by tagged template literal in imported module #6121

Closed
broofa opened this issue Apr 13, 2021 · 3 comments
Labels
Stale Inactive issues

Comments

@broofa
Copy link

broofa commented Apr 13, 2021

馃悰 bug report

[Similar issue as reported in #4559 and #5525. Opening a new report, with attached SSCCE]

It appears that certain template string patterns will break parcel build, causing the above error (but not break with the dev server).

馃捇 SSCCE

See attached
parcel_bug.zip
for minimal, reproduceable, and verifiable example. Unzip and install as follows...

$ unzip -l parcel_bug.zip
Archive:  parcel_bug.zip
  Length      Date    Time    Name
---------  ---------- -----   ----
        0  04-13-2021 08:23   parcel_bug/
      144  04-13-2021 08:10   parcel_bug/.babelrc
      132  04-13-2021 08:04   parcel_bug/index.html
        0  04-13-2021 07:54   parcel_bug/js/
      375  04-13-2021 08:20   parcel_bug/package.json
      103  04-13-2021 07:55   parcel_bug/js/index.js
      124  04-13-2021 07:55   parcel_bug/js/simplur.js
---------                     -------
      878                     7 files

$ unzip parcel_bug.zip
# etc...

$ cd parcel_bug

$ npm i
# etc...

Now do ...

parcel index.html

... and open browser to http://localhost:1234 .

Note: No errors in developer console (works as expected)

Next, do...

$ parcel build index.html

$ npx static-server dist

... and open browser to http://localhost:9080.

Note: "Uncaught TypeError: Object.defineProperty called on non-object" appears in console.

Discussion

This appears to be triggered by the tagged template strings in imported modules. For example...

  • If you inline function simplur() {...} in index.js (so index.js doesn't have to import simplur), the error goes away.

馃實 Your Environment

$ npx envinfo --system --browsers --npmPackages --binaries
npx: installed 1 in 1.53s

  System:
    OS: macOS 11.1
    CPU: (8) x64 Apple M1
    Memory: 397.64 MB / 16.00 GB
    Shell: 5.1.0 - /usr/local/bin/bash
  Binaries:
    Node: 14.16.1 - ~/.nvm/versions/node/v14.16.1/bin/node
    npm: 6.14.12 - ~/.nvm/versions/node/v14.16.1/bin/npm
  Browsers:
    Chrome: 89.0.4389.114
    Firefox: 86.0
    Safari: 14.0.2
  npmPackages:
    @babel/core: 7.13.15 => 7.13.15
    @parcel/babel-plugin-transform-runtime: 2.0.0-nightly.1823 => 2.0.0-nightly.1823
    parcel: 2.0.0-nightly.636 => 2.0.0-nightly.636
@broofa
Copy link
Author

broofa commented Apr 13, 2021

Update: Narrowing this down further, it looks like this is caused by the interaction of @babel/preset-env and @parcel/babel-preset-env in .babelrc. I'm not sure how/why I ended up with both of those in there, but removing the former fixes the problem in the SSCCE here. However doing so in the actual project where I ran into this is causing other issues, so I'm going to leave this open for the time being.

@broofa
Copy link
Author

broofa commented Apr 13, 2021

Well, the other problem went away after removing @babel/preset-env from .babelrc, and then doing rm -fr .parcel-cache node-modules package-lock.json && npm install. 'Not sure what was going on there. 馃し

I'm going to leave this open because...

  1. Bugs that only occur during the build process quickly undermine the trust-worthiness of a bundler.
  2. The pain of diagnosing this was pretty high. The error message and stack were completely detached from what was actually causing the problem. This necessitated a lot of trial-and-error debugging, with a lot of waiting around for the build process to run.
  3. The bug occurs deep inside the boilerplate code injected by Parcel/Babel. I'm pretty sure there's a check that can be added somewhere to help surface this earlier and with a more relevant error message.

@github-actions
Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs.

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

No branches or pull requests

1 participant