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

Building in webpack throws error #21

Closed
KyleAMathews opened this issue Nov 13, 2015 · 26 comments
Closed

Building in webpack throws error #21

KyleAMathews opened this issue Nov 13, 2015 · 26 comments

Comments

@KyleAMathews
Copy link

ERROR in ./~/glify/index.js
Module not found: Error: Cannot resolve module 'fs' in /root/RelateRocket/webapp/node_modules/glify
 @ ./~/glify/index.js 5:9-22
@KyleAMathews
Copy link
Author

The answer apparently is to add some configuration to my webpack config file. It'd be nice if this was documented.

@gnavvy
Copy link
Contributor

gnavvy commented Nov 13, 2015

Known issue: mapbox/mapbox-gl-js#1649

@shanecav
Copy link

@KyleAMathews What configuration did you add to webpack to make it work? I'm having the same issue.

The fix suggested at mapbox/mapbox-gl-js#1649 (adding node: { fs: "empty" } to my webpack config) allowed it to be bundled without errors, but when I view the app in browser I get "Uncaught TypeError: fs.readFileSync is not a function". I see that this is an ongoing issue with mapbox/mapbox-gl-js, but I'm curious if you found a way around it for the time being.

@KyleAMathews
Copy link
Author

Shane, I didn't ever get it to work actually :-)
On Wed, Dec 23, 2015 at 3:25 AM Shane Cavaliere notifications@github.com
wrote:

@KyleAMathews https://github.com/KyleAMathews What configuration did
you add to webpack to make it work? I'm having the same issue.

The fix suggested at mapbox/mapbox-gl-js#1649
mapbox/mapbox-gl-js#1649 (adding node: { fs:
"empty" } to my webpack config) allowed it to be bundled without errors,
but when I view the app in browser I get "Uncaught TypeError:
fs.readFileSync is not a function".


Reply to this email directly or view it on GitHub
#21 (comment).

@imgettingdeported
Copy link

has anyone been able to build successfully with webpack?

@yuvadm
Copy link

yuvadm commented Feb 11, 2016

@lafin do you have a complete example for that? I've added the config, but I'm still stuck with the fs.readFileSync problem.

@yuvadm
Copy link

yuvadm commented Feb 11, 2016

thanks for the repo @lafin! unfortunately I can't see any hints as to why this error is still popping up. Any idea where exactly this call is made to the fs module?

@yuvadm
Copy link

yuvadm commented Feb 11, 2016

It's unclear why despite using

{
  test: /\.js$/,
  include: path.resolve(__dirname, 'node_modules/mapbox-gl/js/render/shaders.js'),
  loader: 'transform/cacheable?brfs'
},

I'm still getting

ERROR in ./~/react-map-gl/~/mapbox-gl/js/render/shaders.js
Module not found: Error: Cannot resolve module 'fs' in .../node_modules/react-map-gl/node_modules/mapbox-gl/js/render
 @ ./~/react-map-gl/~/mapbox-gl/js/render/shaders.js 3:9-22

@yuvadm
Copy link

yuvadm commented Feb 11, 2016

@lafin Yeah I see the problem, react-map-gl is bringing in mapbox-gl as a subdependency, so the paths aren't matching.

@vicapow
Copy link
Contributor

vicapow commented Feb 19, 2016

Hey @lafin, I tried to run the demo, but I'm getting some errors. Did you miss some deps?

Module build failed: ReferenceError: Promise is not defined

@yuvadm
Copy link

yuvadm commented Feb 20, 2016

@vicapow there might be some polyfill package missing, maybe es6-promise or babel-polyfill?

@cezary
Copy link

cezary commented Mar 8, 2016

@shanecav @imgettingdeported @KyleAMathews @yuvadm I was able to get it working with webpack by replacing mapbox-gl with a webpack-compatible fork I made:

Install cezary/mapbox-gl-js#webpack, worker-loader, shader-loader and json-loader.
In your webpack config file set resolve.alias to

{
  'mapbox-gl/js/geo/transform': path.resolve('./node_modules/mapbox-gl/js/geo/transform'),
  'mapbox-gl': path.resolve('./node_modules/mapbox-gl')
}

and add

{ test: /\.worker.js$/, loader: 'worker', query: { inline: true }},
{ test: /\.glsl$/, loader: 'shader' },
{ test: /\.json$/, loader: 'json' }

to your loaders.

The fork hasn't been kept in sync with original, but you can probably replicate the changes I made here.

@Splact
Copy link

Splact commented Mar 10, 2016

@cezary I tried your solution but with no results. Now I get this message when I execute webpack:

ERROR in multi app
Module not found: Error: Cannot resolve 'file' or 'directory' PROJECTROOT\app in PROJECTROOT
 @ multi app

Any ideas?

@joewood
Copy link

joewood commented Apr 18, 2016

Not sure if this was solved, but I'm building with webpack successfully. The config part of interest is:

var path = require("path");
var webpack = require("webpack");
var transform = require("transform-loader");

module.exports = {
::  ::
  resolve: {
   ::                ::
        alias: {
            webworkify: 'webworkify-webpack'
        }
    },
    module: {
        loaders: [
            {
                test: /render[\/\\]shaders\.js$/,
                loader: 'transform/cacheable',
                query: "brfs"
            },
            {
                test: /[\/\\]webworkify[\/\\]index.js\.js$/,
                loader: 'worker'
            },

I also had to pull in a bunch of dev dependencies:

    "babel-core": "^6.7.6",
    "babel-loader": "^6.2.4",
    "babel-preset-es2015": "^6.6.0",
    "babel-preset-react": "^6.5.0",
    "babel-preset-stage-0": "^6.5.0",
    "bootstrap-webpack": "^0.0.5",
    "transform-loader": "^0.2.3",
    "webworkify-webpack": "^1.0.6"

@ankitduseja
Copy link

ankitduseja commented May 16, 2016

@joewood I followed your webpack config but now I am getting this:
Error: Cannot find module 'gl' [1] at Function.Module._resolveFilename (module.js:438:15) [1] at Function._module3.default._resolveFilename (/node_modules/require-hacker/babel-transpiled-modules/require hacker.js:403:34) [1] at Function.module._load (/node_modules/piping/lib/launcher.js:24:23) [1] at Module.require (module.js:466:17) [1] at require (internal/module.js:20:19) [1] at Object.<anonymous> (/node_modules/mapbox-gl/js/util/canvas.js:6:10) [1] at Module._compile (module.js:541:32) [1] at Module._extensions..js (module.js:550:10) [1] at require.extensions.(anonymous function) (/node_modules/babel-register/lib/node.js:166:7) [1] at Object._module3.default._extensions.(anonymous function) [as .js] (/node_modules/require-hacker/babel-transpiled-modules/require hacker.js:250:71)

I see a similar error here:
mapbox/mapbox-gl-js#828 (comment)
mapbox/mapbox-gl-js#1649

@tsemerad
Copy link
Contributor

tsemerad commented May 24, 2016

@ankitduseja I'm getting the same Cannot resolve module 'gl' but also Cannot resolve module 'autobind-decorator':

ERROR in ./~/react-map-gl/dist/map.react.js
Module not found: Error: Cannot resolve module 'autobind-decorator' in node_modules/react-map-gl/dist
 @ ./~/react-map-gl/dist/map.react.js 45:25-54

ERROR in ./~/react-map-gl/dist/overlays/draggable-points.react.js
Module not found: Error: Cannot resolve module 'autobind-decorator' in node_modules/react-map-gl/dist/overlays
 @ ./~/react-map-gl/dist/overlays/draggable-points.react.js 36:25-54

ERROR in ./~/react-map-gl/dist/map-interactions.react.js
Module not found: Error: Cannot resolve module 'autobind-decorator' in node_modules/react-map-gl/dist
 @ ./~/react-map-gl/dist/map-interactions.react.js 34:25-54

ERROR in ./~/mapbox-gl/js/util/canvas.js
Module not found: Error: Cannot resolve module 'gl' in node_modules/mapbox-gl/js/util
 @ ./~/mapbox-gl/js/util/canvas.js 6:9-22

@shanecav
Copy link

@tsemerad I'm also getting the Cannot resolve module 'autobind-decorator' error. I had to npm install --save autobind-decorator to get it to work.

However I'm not getting the Cannot resolve module 'gl' error. See my comment in the corresponding mapbox-gl-js issue.

@tiagocpontesp
Copy link

Also had to jspm install npm:autobind-decorator.

@tsemerad
Copy link
Contributor

tsemerad commented May 31, 2016

@shanecav I solved the Cannot resolve module 'gl' issue. It turns out my webpack config was adding mapbox-gl to externals. Updating my externals to just a few explicit packages (rather than a function that was auto-generating a list of packages to add to externals) fixed it.

@infacq
Copy link

infacq commented Jun 5, 2016

@tsemerad do you mind sharing your webpack.config

@cazzer
Copy link

cazzer commented Jun 7, 2016

In case any of you are seeing Cannot read property "call" of undefined or similar, try grabbing webworkify-webpack@1.0.6. This, in addition to Mapbox's own steps for webpack, did the trick for me. Thanks to Mike Williamson's blog post and the comments therein for pointing it out.

For anyone interested, I only had to add the following to my webpack.config:

module.exports = {
  resolve: {
    alias: {
      webworkify: 'webworkify-webpack'
    },
    ...
  },
  module: {
    loaders: [
      {
        test: /\.json$/,
        loader: 'json-loader'
      }, {
        test: /use_program\.js$/,
        loader: 'transform/cacheable?brfs'
      },
      ...
    ],
    postLoaders: [
      {
        include: /node_modules\/mapbox-gl/,
        loader: 'transform',
        query: 'brfs'
      }
    ]
  },
  ...
}

I also had to install gl as others have suggested.

@tsemerad
Copy link
Contributor

@infacq Sorry for the delay. My webpack config is a bit convoluted, but I posted it in a gist here:
https://gist.github.com/tsemerad/41fd8d8c61762b3a48a50e42ce4256c0

caseycesari added a commit to caseycesari/ebird-hotspot-viewer that referenced this issue Jun 29, 2016
* Add Mapbox GL and related libraries required to serve
maps from Webpack.
* Update Webpack config based on Mapbox example and
https://mikewilliamson.wordpress.com/2016/02/24/using-mapbox-gl-and-webpack-together/,
and visgl/react-map-gl#21 (comment).
* Create map component and add to SightingsList component.

Closes #8
@Stupidism
Copy link

I found myself the smallest change from a webpack config to go through this error, but I got this sources.map is not a function error.
Anybody help me?

   resolve: {
+    alias: {
+      webworkify: 'webworkify-webpack'
+    }
   },
loaders = [{
+{
+  test: /mapbox-gl.+\.js$/,
+  loader: 'transform/cacheable?brfs'
+},
]

@kachkaev
Copy link

kachkaev commented Jul 25, 2016

I've tried adding a simple react-map-gl into a new app using react-boilerplate but got stuck with an empty single-colour map in dev mode.

MWE here: https://github.com/kachkaev/react-boilerplate-react-map-gl-mwe

A related issue seems to be here: #96

Has anyone used the same boilerplate? Any ideas?

@ibgreen
Copy link
Contributor

ibgreen commented Aug 26, 2016

Given the new instructions from mapbox on how to build with webpack (see README for link) I will close this for now.

If there are react-map-gl specific issues with webpack, the best approach would be to open a PR with a small example, see #112

@ibgreen ibgreen closed this as completed Aug 26, 2016
@Jinnified
Copy link

@ankitduseja could you please tell me how did you solve that Cannot find module 'gl' issue? it appears npm hangs when i am trying to install the gl module

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