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

Running 'parcel build' creates js file with errors #5091

Open
fab7jj opened this issue Sep 2, 2020 · 15 comments
Open

Running 'parcel build' creates js file with errors #5091

fab7jj opened this issue Sep 2, 2020 · 15 comments

Comments

@fab7jj
Copy link

fab7jj commented Sep 2, 2020

I have the below scripts in my package.json:

"scripts": {
    "build": "parcel build src/index.js",
    "start": "parcel watch src/index.js"
  }

Now when I run 'yarn start' everything is fine but when I run 'yarn build', the index.js produced by parcel in the dist folder is throwing the below error in the google chrome console:

Uncaught TypeError: Object prototype may only be an Object or null: undefined

I am thinking maybe something is going wrong during the minification process but I am a bit lost on how to debug such issue.

I noticed that the issue is being caused when importing the '@progress/kendo-react-inputs' package like below:

import { MaskedTextBox, RadioGroup } from '@progress/kendo-react-inputs';

But I also have another app that uses create-react-app rather than parcel and imports such package and that works well

Can someone please shed some light on this?

Thanks a lot!

@mischnic
Copy link
Member

mischnic commented Sep 2, 2020

Which Parcel version are you using?

@fab7jj
Copy link
Author

fab7jj commented Sep 3, 2020

@mischnic I am using parcel 2.. I had a nightly build installed, then I updated to the latest version by using the following command: yarn add -D parcel@next but still the issue persists, so I even tried to install the latest nightly by running the following command: yarn add -D parcel@nightly so now I ended up with this version installed: "parcel": "^2.0.0-nightly.387" but still the issue persists. Thanks a lot... do you have any clue how I can go about this please, since it is stopping me from deploying my react app?

@fab7jj
Copy link
Author

fab7jj commented Sep 3, 2020

@mischnic I checked a bit more my stuff and I highly believe that this is a bug in parcel 2, since as said I have another app which uses create-react-app and imports the same version of such package and that produces a minified production version just fine. If I can help you out by providing any further information just let me know, since at this stage I am stuck to be honest.

@mischnic
Copy link
Member

mischnic commented Sep 3, 2020

Please provide some code sample. I've tried the example code on https://www.telerik.com/kendo-react-ui/components/inputs/radiobutton/ but that works fine

@fab7jj
Copy link
Author

fab7jj commented Sep 3, 2020

Hmm that is very strange, so you tried running 'parcel build' and the generated js file had no errors? Since for me once I try to import the kendo-react-inputs like for example: import { MaskedTextBox, RadioGroup } from '@progress/kendo-react-inputs'; the mentioned error pops up. Please kindly see the below code sample:

index.js (this is the entry point)

import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './components/App';

ReactDOM.render(
  <React.StrictMode>
    <App />
  </React.StrictMode>,
  document.getElementById('enteractiveConversationsPlayerApp')
);

App.js (this is the component)

import React from 'react';
import { MaskedTextBox, RadioGroup } from '@progress/kendo-react-inputs';

function App(props) {

    return null;
}

export default App;

package.json (note that i reverted the parcel version back to the one I had prior to this issue)

{
  "name": "enteractive-conversations-player-app",
  "version": "1.0.0",
  "private": true,
  "license": "MIT",
  "scripts": {
    "build": "parcel build src/index.js",
    "release": "cross-env NODE_ENV=release parcel build src/index.js",
    "stage": "cross-env NODE_ENV=staging parcel build src/index.js",
    "start": "parcel watch src/index.js"
  },
  "devDependencies": {
    "cross-env": "^7.0.2",
    "parcel": "^2.0.0-nightly.291"
  },
  "dependencies": {
    "@fortawesome/fontawesome-svg-core": "^1.2.30",
    "@fortawesome/free-solid-svg-icons": "^5.14.0",
    "@fortawesome/react-fontawesome": "^0.1.11",
    "@progress/kendo-drawing": "^1.8.1",
    "@progress/kendo-react-animation": "^3.15.0",
    "@progress/kendo-react-buttons": "^3.14.0",
    "@progress/kendo-react-conversational-ui": "^3.14.0",
    "@progress/kendo-react-dropdowns": "^3.15.0",
    "@progress/kendo-react-form": "^3.15.0",
    "@progress/kendo-react-inputs": "^3.15.0",
    "@progress/kendo-react-intl": "^3.14.0",
    "@progress/kendo-react-labels": "^3.15.0",
    "@progress/kendo-theme-material": "^3.16.0",
    "axios": "^0.19.2",
    "babel-runtime": "^6.26.0",
    "fingerprintjs2": "^2.1.0",
    "moment": "^2.27.0",
    "qs": "^6.9.4",
    "react": "^16.13.1",
    "react-dom": "^16.13.1",
    "twilio-chat": "^3.4.0"
  }
}

Such code produces the below error when I run the command: 'yarn build'

parcel build error

@fab7jj
Copy link
Author

fab7jj commented Sep 4, 2020

@mischnic please note that after further investigation I noticed that if I add the flag: --no-scope-hoist the issue is resolved, but I am not sure what this does exactly. Thanks a lot

@fab7jj
Copy link
Author

fab7jj commented Sep 17, 2020

@mischnic any news on this please?

@mischnic
Copy link
Member

mischnic commented Dec 6, 2020

Sorry for the long delay, but the example you posted works fine for me.

@realvictorprm
Copy link

I'm running into the exact same problem with adding --no-scope-hoist being the fix for that problem. Using in my package.json "parcel": "^2.0.0-beta.1".

Unfortunately it's not possible for me to post the code as it's not open source.

@lierdakil
Copy link

lierdakil commented Mar 20, 2021

Running into this with parcel-2.0.0-beta.2 in https://github.com/TypeStrong/atom-typescript/. The error is thrown from this code fragment (non-minified):

// ASSET: node_modules/inherits/inherits_browser.js
var $c6c7720fe577540e015650540ece1eb7$exports, $c6c7720fe577540e015650540ece1eb7$executed = false;
function $c6c7720fe577540e015650540ece1eb7$exec() {
  $c6c7720fe577540e015650540ece1eb7$exports = {};
  if (typeof Object.create === 'function') {
    // implementation from standard node.js 'util' module
    $c6c7720fe577540e015650540ece1eb7$exports = function inherits(ctor, superCtor) {
      if (superCtor) {
        ctor.super_ = superCtor;
        ctor.prototype = Object.create(superCtor.prototype, {
          constructor: {
            value: ctor,
            enumerable: false,
            writable: true,
            configurable: true
          }
        });
      }
    };
  } else {

Specifically, superCtor.prototype is apparently undefined.

Stack Trace

At Object prototype may only be an Object or null: undefined

TypeError: Object prototype may only be an Object or null: undefined
    at Function.create (<anonymous>)
    at inherits (/home/livid/github/other/atom-typescript/dist/main.js:27274:33)
    at $1eb49f8fe789659e20000b0d5afc791a$exec (/home/livid/github/other/atom-typescript/dist/main.js:28188:3)
    at $1eb49f8fe789659e20000b0d5afc791a$init (/home/livid/github/other/atom-typescript/dist/main.js:28600:5)
    at $ba8d383b7628bbc4c953fa5229c1ecfc$exec (/home/livid/github/other/atom-typescript/dist/main.js:28848:48)
    at $ba8d383b7628bbc4c953fa5229c1ecfc$init (/home/livid/github/other/atom-typescript/dist/main.js:28860:5)
    at Object.<anonymous> (/home/livid/github/other/atom-typescript/dist/main.js:28872:12)
    at Object.<anonymous> (/home/livid/github/other/atom-typescript/dist/main.js:29581:4)
    at Object.<anonymous> (/home/livid/github/other/atom-typescript/dist/main.js:31756:3)
/// NOTE: below is Atom internals, probably not relevant
    at Module.get_Module._compile (/home/livid/.local/share/atom/resources/app/static/<embedded>:11:147404)
    at Object.value [as .js] (/home/livid/.local/share/atom/resources/app/static/<embedded>:11:150952)
    at Module.load (internal/modules/cjs/loader.js:645:32)
    at Function.Module._load (internal/modules/cjs/loader.js:560:12)
    at Module.require (/app.asar/static/index.js:72:46)
    at require (/home/livid/.local/share/atom/resources/app/static/<embedded>:11:146720)
    at Object.<anonymous> (/home/livid/github/other/atom-typescript/loader.js:5:20)
    at Object.<anonymous> (/home/livid/github/other/atom-typescript/loader.js:8:3)
    at Module.get_Module._compile (/home/livid/.local/share/atom/resources/app/static/<embedded>:11:147404)
    at Object.value [as .js] (/home/livid/.local/share/atom/resources/app/static/<embedded>:11:150952)
    at Module.load (internal/modules/cjs/loader.js:645:32)
    at Function.Module._load (internal/modules/cjs/loader.js:560:12)
    at Module.require (/app.asar/static/index.js:72:46)
    at require (internal/modules/cjs/helpers.js:16:16)
    at customRequire (/home/livid/.local/share/atom/resources/app/static/<embedded>:1:697034)
    at requireModule (/home/livid/.local/share/atom/resources/app/static/<embedded>:14:1122705)
    at Package.requireMainModule (/home/livid/.local/share/atom/resources/app/static/<embedded>:11:3501323)
    at Package.activateNow (/home/livid/.local/share/atom/resources/app/static/<embedded>:11:3489307)
    at /home/livid/.local/share/atom/resources/app/static/<embedded>:14:2607
    at Function.simpleDispatch (/home/livid/.local/share/atom/resources/app/static/<embedded>:11:1190181)
    at Emitter.emit (/home/livid/.local/share/atom/resources/app/static/<embedded>:11:1191622)

I am attaching an unminified main.js: main.js.gz

Beta 1 was working fine.

@lierdakil
Copy link

Here is the relevant upstream issue: isaacs/inherits#38

@lierdakil
Copy link

Ping. I've ran into this again on another project. Any updates?

@lierdakil
Copy link

lierdakil commented Apr 16, 2021

FWIW, after a little more investigation, I've tracked this down to the glob package, wherein in the version where the issue manifests we see (line 28157 in the main.js attached above)

$1eb49f8fe789659e20000b0d5afc791a$var$EE = {};

wherein when built with parcel 2.0.0-beta.1 we instead see in the corresponding place

$b1d16ad7d6917ec5b6516c1ffa761e$var$EE = _events.EventEmitter;

However, this doesn't seem to be related to any changes in the glob package, in all versions I've checked the relevant line reads

var EE = require('events').EventEmitter

indeed, this line has been last touched 6 years ago

Curiously, at the top of the bundle where the issue manifests, we see var EventEmitter = require("events").EventEmitter;, and this variable is never mentioned in the rest of the file.

Building with --no-scope-hoist indeed sidesteps this issue (mostly because the code isn't transformed), so this tells me there's perhaps a bug in the hoisting code somewhere.

@aminya
Copy link
Contributor

aminya commented Jun 2, 2021

@lierdakil The issue seems like #6242. Have you tried the latest nightly to see if this is solved?

@lierdakil
Copy link

Considering I apparently lack a way to consistently reproduce the issue, since it manifested in beta1 but not beta2 less than an hour ago, I regrettably can't confirm whether it's fixed anywhere or not.

Hyuchia added a commit to Monogatari/Monogatari that referenced this issue Jan 12, 2022
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

5 participants