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

_typeof is not defined #3422

Closed
bensleveritt opened this issue Oct 20, 2016 · 23 comments
Closed

_typeof is not defined #3422

bensleveritt opened this issue Oct 20, 2016 · 23 comments

Comments

@bensleveritt
Copy link

bensleveritt commented Oct 20, 2016

Getting a _typeof is not defined error when using babel-preset-es2015 in Webpack. Not using the preset removes the error.

v0.26.0:

Steps to Trigger Behavior

  1. Set up Webpack, Babel, Mapbox-gl as per my repo.
  2. npm start to start webpack-dev-server.
  3. Observe console log errors:
Uncaught ReferenceError: _typeof is not defined
exports.clone @ blob:http://localhost:3000/c231e9bd-0ca6-4a10-8b58-eecdc79fe25d:1
StyleDeclaration @ blob:http://localhost:3000/c231e9bd-0ca6-4a10-8b58-eecdc79fe25d:1
setPaintProperty @ blob:http://localhost:3000/c231e9bd-0ca6-4a10-8b58-eecdc79fe25d:1
set @ blob:http://localhost:3000/c231e9bd-0ca6-4a10-8b58-eecdc79fe25d:1
StyleLayer @ blob:http://localhost:3000/c231e9bd-0ca6-4a10-8b58-eecdc79fe25d:1
FillStyleLayer @ blob:http://localhost:3000/c231e9bd-0ca6-4a10-8b58-eecdc79fe25d:1
StyleLayer.create @ blob:http://localhost:3000/c231e9bd-0ca6-4a10-8b58-eecdc79fe25d:1
t @ blob:http://localhost:3000/c231e9bd-0ca6-4a10-8b58-eecdc79fe25d:1
setLayers @ blob:http://localhost:3000/c231e9bd-0ca6-4a10-8b58-eecdc79fe25d:1
Actor.receive @ blob:http://localhost:3000/c231e9bd-0ca6-4a10-8b58-eecdc79fe25d:1

Expected Behavior

Basic map is displayed over beige background.

Actual Behavior

Beige background is displayed.

@jfirebaugh
Copy link
Contributor

Looks like a bug in babel (babel/babel#4125, not sure why this is closed). The dist mapbox-gl.js file does not use ES2015, please exclude it from transpilation.

@bensleveritt
Copy link
Author

bensleveritt commented Oct 20, 2016

I've excluded it, thanks for the help.

Edit (to help people in the future):
Add exclude: /(node_modules)/ to the babel loader definition in webpack.config.

@rotoglup
Copy link

Add exclude: /(node_modules)/ to the babel loader definition in webpack.config.

FWIW, I've got bitten by this whole exclusion, better exclude only mapbox-gl with exclude: /mapbox-gl/

@caesarsol
Copy link

Hitting the same error here, it was hard to find because one minified becomes s is not a function...

Waiting for the babel issue, in the meantime exclude: /mapbox-gl/ is the way.

@digitalkaoz
Copy link

digitalkaoz commented Oct 31, 2018

anyone has an idea how to solve it without excluding it from babeling? babel/babel#4125 is closed and locked without a resolution CRA solved it somehow by excluding transform-typeof-symbol but it wont work with react-static (which uses babel7) when excluding exclude: ['@babel/plugin-transform-typeof-symbol']

so im more then confused...excluding is the worst option, cant it be solved in mapboxgl?

oleksii-leonov added a commit to oleksii-leonov/webpacker that referenced this issue Jan 16, 2019
New `nodeModules` loader significantly change behavior.
It's specified in **Breaking changes** section but description is quite small.

As example, @javan have issue with `nodeModules` loader (rails#1892). Also, in my build it breaks `mapbox-gl` package (mapbox/mapbox-gl-js#3422).

This PR adds more details to `CHANGELOG.md` about `nodeModules` loader and receipt to keep previous behavior.
@cyrilchapon
Copy link

cyrilchapon commented Apr 10, 2019

This is still an issue using

  • mapbox-gl 0.53.1
  • react-map-gl 4.1.1
  • parcel-bundler 1.12.3

Getting

Uncaught ReferenceError: _typeof is not defined

From webworker

@fabiobarboza7
Copy link

fabiobarboza7 commented Jun 6, 2019

It sometimes happens when you are trying to read some javascript before load the js file.

@CharlieMartell
Copy link

Seeing this aswell on Chrome 76 mapbox-gl@1.2.0

@CharlieMartell
Copy link

Worked around this by adding exclude: /mapbox-gl/ into babel-loader webpack rules

@KevinColemanInc
Copy link

For rails devs scratching their heads at this, I found this fixed the problem:
in environment.js

environment.loaders.delete('nodeModules')

related content:
https://github.com/rails/webpacker/blob/54c3ca9245e9ee330f8ca63b447c202290f7b624/docs/v4-upgrade.md#excluding-node_modules-from-being-transpiled-by-babel-loader

albertchae added a commit to rubyforgood/freeforest that referenced this issue Apr 5, 2020
@jordymeow
Copy link

Was anybody able to do it using Parcel, and Babel 7? @cyrilchapon, did you find a way? It would be awesome to find a solution to this.

@cyrilchapon
Copy link

@jordymeow nah I just gave up on parcel.
Found out that this 0-config stuff is just basically not suitable for complex projects involving complex libs like mapbox

@willallendev
Copy link

willallendev commented May 20, 2020

I created my project with create-react-app, so I've got no direct access to the webpack.config file.

I did the following:

  1. Add react-app-rewired to my project in order to override webpack.config in node_modules/react-scripts/config. This will be true if you create your project the same way as I did (https://github.com/timarney/react-app-rewired) make sure to follow all the instructions and modify the scripts in your package.json
  2. Add customize-cra to my project (https://github.com/arackaf/customize-cra#with-webpack) and follow the instructions
  3. In your newly created config-overrides.js file use the "babelExclude" helper function from customize-cra package in order to exclude mapbox-gl from babel loader (make sure to write the path correctly, you may want to use "path" package).
  4. This might do the trick for you

however depending on the structure use in your webpack.config files in node_modules/react-scripts/config the helper function "babelExclude" might not be able to reference your babel loader definition and you will get an error like “cannot set property exclude of undefined” if that happens you will have to do what I did to make it work, which is checking your webpack.config files and figuring out where in the structure you will be able to write/override the exclude sentence (see my config-overrides.js below).

const path = require('path');

const babelExclude = (exclude, config) => {
  config.module.rules[2].oneOf[2].use[1].options.exclude = exclude;
  return config;
};

module.exports = function override(config) {
  config = babelExclude(path.resolve('node_modules/mapbox-gl'), config);
  return config;
};

My version of "react-scripts": "2.0.0" (this is the one package that defines the webpack.config file for you)

Not pretty but that did the trick for me without having to eject. You may want to remove de ^ sign in front of the version of react-scripts in your package.json. If the webpack,config changes you project might break again, or at least be aware that you will have to update config-overrides.js accordingly.

Hope it helps someone!

@zzzev
Copy link

zzzev commented Jun 5, 2020

We're using parcel & babel 7, and fixed this by narrowing the scope of browsers we include in the browserslist property of our package.json. Some of the browsers we were including were causing the transform-typeof-symbol plugin to be applied, which is what causes this (something about this plugin doesn't work properly when typeof is used inside the web worker used by mapbox).

@andrew-j-roberts
Copy link

Hey @zzzev , do you mind posting your package.json file?

I'd love to see if this solves my issue too.

@zzzev
Copy link

zzzev commented Jun 8, 2020

The browserslist part:

  "browserslist": {
    "production": [
      "last 3 chrome versions",
      "last 3 firefox versions",
      "last 3 safari versions"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },

We're using parcel 1.12.4, with no explicit babel dep and no babelrc file.

@sachinpatil55
Copy link

The browserslist part:

  "browserslist": {
    "production": [
      "last 3 chrome versions",
      "last 3 firefox versions",
      "last 3 safari versions"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },

We're using parcel 1.12.4, with no explicit babel dep and no babelrc file.

This solution worked for me thanks @zzzev

@daveycakes
Copy link

For rails devs scratching their heads at this, I found this fixed the problem:
in environment.js

environment.loaders.delete('nodeModules')

related content:
https://github.com/rails/webpacker/blob/54c3ca9245e9ee330f8ca63b447c202290f7b624/docs/v4-upgrade.md#excluding-node_modules-from-being-transpiled-by-babel-loader

You are a wonderful human being

@Fradomati
Copy link

The browserslist part:

  "browserslist": {
    "production": [
      "last 3 chrome versions",
      "last 3 firefox versions",
      "last 3 safari versions"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },

We're using parcel 1.12.4, with no explicit babel dep and no babelrc file.

This solution worked for me thanks @zzzev

Yeah, me too but, might this be a problem in the future?

@gooin
Copy link

gooin commented Dec 7, 2020

The browserslist part:

  "browserslist": {
    "production": [
      "last 3 chrome versions",
      "last 3 firefox versions",
      "last 3 safari versions"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },

We're using parcel 1.12.4, with no explicit babel dep and no babelrc file.

It works for me too. webpack version ^5.8.0 , babel verison ^7.12.8

@jswelsh
Copy link

jswelsh commented Dec 21, 2020

The browserslist part:

  "browserslist": {
    "production": [
      "last 3 chrome versions",
      "last 3 firefox versions",
      "last 3 safari versions"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },

We're using parcel 1.12.4, with no explicit babel dep and no babelrc file.

This worked for me

@cacheflow
Copy link

For rails devs scratching their heads at this, I found this fixed the problem:
in environment.js

environment.loaders.delete('nodeModules')

related content:
https://github.com/rails/webpacker/blob/54c3ca9245e9ee330f8ca63b447c202290f7b624/docs/v4-upgrade.md#excluding-node_modules-from-being-transpiled-by-babel-loader

I ran into this same issue with another module I'm using. This fixed it!

@Sioomak
Copy link

Sioomak commented Mar 19, 2021

Excluding quagga from babel-loader in webpack.mix.js fixed the issue for me:

Screenshot (11)

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

No branches or pull requests