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 2 nightly 766: running app fails with cannot read property 'init' of undefined #6642

Closed
jessabyrne opened this issue Jul 26, 2021 · 9 comments

Comments

@jessabyrne
Copy link

jessabyrne commented Jul 26, 2021

🐛 bug report

In the latest nightly, the app builds but when running there is an error Uncaught TypeError: Cannot read property 'init' of undefined

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

package.json

    "@parcel/transformer-raw": "^2.0.0-nightly.778",
    "@parcel/transformer-typescript-tsc": "^2.0.0-nightly.778",
    "parcel": "^2.0.0-nightly.776",

.parcelrc

{
  "extends": "@parcel/config-default",
  "transformers": {
    "*.{ts,tsx}": ["@parcel/transformer-typescript-tsc"],
    "*.{jpg,png,svg}": ["@parcel/transformer-raw"]
  }
}

babel.config.json

{
  "presets": [
    "@babel/preset-env",
    "@babel/preset-react",
    "@babel/preset-typescript"
  ]
}

🤔 Expected Behavior

App should run

😯 Current Behavior

Uncaught TypeError: Cannot read property 'init' of undefined
    at Object.init (index.cc2d3c60.js:43699)
    at esmodule-helpers.js:16
    at Array.forEach (<anonymous>)
    at Object.exports.exportAll (esmodule-helpers.js:10)
    at Object.1gx6a.@sentry/browser (index.ts:1)
    at newRequire (index.cc2d3c60.js:71)
    at localRequire (index.cc2d3c60.js:83)
    at Object.7H1bM.@sentry/react (index.ts:1)
    at newRequire (index.cc2d3c60.js:71)
    at localRequire (index.cc2d3c60.js:83)

Where the line flagged is:

exports.reportErrorToSentry = reportErrorToSentry;

},{"@sentry/react":"1gx6a"}],"1gx6a":[function(require,module,exports) {
var parcelHelpers = require("@parcel/transformer-js/src/esmodule-helpers.js");
parcelHelpers.defineInteropFlag(exports);
parcelHelpers.export(exports, "init", ()=>_sdk.init. //HERE IS THE LINE

in esmodules-helper:

exports.exportAll = function(source, dest) {
  Object.keys(source).forEach(function(key) {
    if (key === 'default' || key === '__esModule') {
      return;
    }

    // Skip duplicate re-exports when they have the same value. **THE LINE WITH THE ISSUE**
    if (key in dest && dest[key] === source[key]) {
      return;
    }

    Object.defineProperty(dest, key, {
      enumerable: true,
      get: function() {
        return source[key];
      },
    });
  });

  return dest;
};

🔦 Context

I have removed .parcel-cache, other caches, reinstalled node_modules, etc. The app builds but when running is stuck.

I also attempted using --no-scope-hoist for the build command.

🌍 Your Environment

Software Version(s)
Parcel 2.0.0-nightly.776
Node v16.3.0
npm/Yarn 7.15.1
Operating System osx Big Sur

EDIT:
version of sentry used:
"@sentry/react": "^6.10.0", also tried "@sentry/react": "^6.9.0",

@devongovett
Copy link
Member

Could you provide a small reproduction of the issue? From the stack trace it looks like something in @sentry/react or @sentry/browser but I couldn't reproduce it.

@jessabyrne
Copy link
Author

I don't have a repro, but it does look like if I comment out our initialization of Sentry Sentry.init({ in our index file everything runs as expected. The same code works with parcel 2.0.0-beta.3, but it might be an issue with something on our side.

Either way, sourcemaps still seem to be broken on this nightly version, which was our main motivator for upgrading. Is there a better version to try to get sourcemaps working for TS projects?

@mischnic
Copy link
Member

The same code works with parcel 2.0.0-beta.3, but it might be an issue with something on our side.

That sounds like a regression in Parcel then.

Either way, sourcemaps still seem to be broken on this nightly version, which was our main motivator for upgrading. Is there a better version to try to get sourcemaps working for TS projects?

How are they not working? Are you using tsc and/or Babel? Can you provide a reproduction?

@jessabyrne
Copy link
Author

Using babel and tsc (configuration in the issue description above).

I think it's similar to this issue: #6645

When the app runs, I see this type of code in an average tsx file in the source maps:

"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

var _react = _interopRequireWildcard(require("react"));

@mischnic
Copy link
Member

"@babel/preset-env"

This makes Parcel's scope hoisting ineffective (or even useless), you should use @parcel/babel-preset-env: https://v2.parceljs.org/languages/babel/#extending-the-default-babel-config. It might also cause the init of undefined error.

@jessabyrne
Copy link
Author

jessabyrne commented Jul 27, 2021

That fixed it, thank you! 🎉
Edit: This fixed the sourcemaps issue, however the init error is still around. Reverting to 2.0.0-beta.3.1 for now.

@devongovett
Copy link
Member

I still cannot reproduce this. I tried with the babel and parcel configs listed above and the following code:

import * as Sentry from "@sentry/react";

Sentry.init({
  dsn: "https://examplePublicKey@o0.ingest.sentry.io/0",
});

There's no runtime error when loading in the browser for me.

@playpauseandstop
Copy link

Hi everyone,

Sorry to be late to the party and post comment to closed issue, but I have similar issue with parcel & @sentry/react, when trying to migrate from parcel-bundler@1 to parcel@2.

Please, find the gist with code to reproduce the error: https://gist.github.com/playpauseandstop/44aab02fea0bca15d7b0cf78157ff3c6

I have used clean parcel@nightly version to bundle the code and error is there. I've also tried to include .parcelrc config and use @parcel/transformer-typescript-tsc for transforming .ts and .tsx files, but the error still there.

And the most interesting fact, that in build mode parcel@nightly produced proper bundle and everything works as expected.

parcel serve

Screen Shot 2021-09-28 at 17 54 01

parcel build + npx serve ...

Screen Shot 2021-09-28 at 18 01 06

@playpauseandstop
Copy link

After release of parcel@2 my previous comment is invalid and now everything works correctly.

Assuming it was finally fixed between nightly 843 and final release, so we’re good now. Thanks!

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

No branches or pull requests

4 participants