parcel: TypeError: Cannot read property 'TYPED_ARRAY_SUPPORT' of undefined #803

🐛 bug report

When I import oidc-client and write “new UserManager({…})” in a parcel bundled project, I get this issue: “Uncaught TypeError: Cannot read property ‘TYPED_ARRAY_SUPPORT’ of undefined” I tried it without parcel and it worked. So the issue should be caused by parcel.

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

{
  "name": "my-project",
  "version": "0.1.0",
  "license": "UNLICENSED",
  "author": "Me",
  "scripts": {
    "start": "parcel src/index.html --no-cache --port 8080",
    "start:build": "http-server dist/ -o",
    "build": "parcel build src/index.html --no-cache"
  },
  "dependencies": {
    "lit-element": "^2.1.0",
    "oidc-client": "^1.7.0"
  },
  "devDependencies": {
    "http-server": "^0.11.1",
    "parcel-bundler": "^1.12.3",
    "parcel-plugin-webcomponents": "^1.2.0"
  },
  "browserslist": [
    "last 2 chrome version",
    "last 2 firefox version",
    "last 2 edge version",
    "last 2 safari version",
    "not dead"
  ]
}

🤔 Expected Behavior

oidc-client should just work.

😯 Current Behavior

image

💁 Possible Solution

No idea

🔦 Context

I just tried to use oidc-client in a parcel bundled project. Everything worked under webpack.

💻 Code Sample

import { UserManager } from 'oidc-client'

const userManager = new UserManager({})

🌍 Your Environment

Software Version(s)
Parcel 1.12.3
Node 11.11.0
npm 6.7.0
Operating System Windows 10

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 1
  • Comments: 16 (6 by maintainers)

Commits related to this issue

Most upvoted comments

Please don’t use <script type="module"> with parcel. There is no reason to do so as Parcel already compiles es6 modules away.

The buffer polyfill for browsers contains this code

Buffer.TYPED_ARRAY_SUPPORT = global.TYPED_ARRAY_SUPPORT !== undefined
  ? global.TYPED_ARRAY_SUPPORT
  : "DEFAULT";

If you run the parcel script in a type="module" script (which is unsupported), Parcel can’t get the global object using this because that’s forbidden in this context. Figuring out the global object is actually not trivial: https://github.com/tc39/proposal-global

Which usually doesn’t work because of this whole parcelRequire bug thing, but (and don’t ask me why) everything works fine if you include a css file first.

Doesn’t work for me… (#1401)