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

Built file in master requires fs #970

Closed
trygveaa opened this issue Mar 18, 2020 · 18 comments · Fixed by #1032
Closed

Built file in master requires fs #970

trygveaa opened this issue Mar 18, 2020 · 18 comments · Fixed by #1032
Assignees
Labels

Comments

@trygveaa
Copy link

mapbox-gl-js version: 1.8.1
mapbox-gl-draw version: master

Steps to Trigger Behavior

  1. Clone this repo and run yarn && yarn build-min
  2. Try to import dist/mapbox-gl-draw.js in a project

Expected Behavior

It should work, without depending on fs.

Actual Behavior

I can't use it because it depends on fs. That is, I'm getting:

ERROR in ./node_modules/@mapbox/mapbox-gl-draw/dist/mapbox-gl-draw.js
Module not found: Error: Can't resolve 'fs' in '/home/trygve/dev/my-project/front/node_modules/@mapbox/mapbox-gl-draw/dist'

If I try to do the same after checking out v1.1.2 it works fine.

@Ecafracs
Copy link

I'm also encountering this issue.
It looks like mapbox-gl-draw depends on @mapbox/geojsonhint, which depends on zaach/jsonlint-lines, which is referring to fs.
@mapbox/geojsonhint is apparently "on pause" as of a year ago.
zaach/jsonlint-line was abandoned 4 years ago, and it looks like mapbox/jsonlint is a fork of a fork of it.

Can somebody who understand what these packages do figure out how to replace these dependencies to not rely on dead code?

trygveaa added a commit to trygveaa/mapbox-gl-draw that referenced this issue Mar 20, 2020
Including fs and path in externals is not sufficient when this is used
in a browser. That will just make rollup leave the requires calls, and
when you try to include this library in a webpack project webpack will
complain that fs is missing.

By providing shims for fs and path, those will be used instead of
require calls, so that fixes the issue. Since no code paths in this
library triggers the code that requires fs or path it's safe to just
shim them out with an empty object.

Fixes mapbox#970
@brendanmc6
Copy link

A fix would be much appreciated! @trygveaa would that PR you've linked fix this issue as well? Or would we need to wait for a downstream fix here?

As others have said, this seems to fix it for me:
import MapboxDraw from '@mapbox/mapbox-gl-draw/dist/mapbox-gl-draw.js';

Here are existing issues I have found:
#850
#844
#626

@trygveaa
Copy link
Author

trygveaa commented Mar 29, 2020

A fix would be much appreciated! @trygveaa would that PR you've linked fix this issue as well? Or would we need to wait for a downstream fix here?

Yes, #977 fixes this issue. However I've written some comments for discussion in it, because I don't think bundling all the dependencies in the single js file is a good idea. Though, that already happens, so there are no downsides of #977 over the current situation.

As others have said, this seems to fix it for me:
import MapboxDraw from '@mapbox/mapbox-gl-draw/dist/mapbox-gl-draw.js';

That works because the issue I'm describing in here doesn't exist in version v1.1.2, which is what is currently on npm. However for master, i.e. the unreleased version, this solution does not work.

Here are existing issues I have found:
#850
#844
#626

To be clear, even though these are related, the issue I'm describing here is not the same as those issues. Those issues is about the main entry point for the package requiring fs and path. That can be worked around by importing the dist file instead as you mentioned. However, this issue is about that even the dist file requires fs and path, so this workaround does not work anymore.

PR #976 fixes what those issues describe, so you don't have to specify the dist file (but #977 is also required for that to work).

@georgir
Copy link

georgir commented Aug 14, 2020

Now v1.2.0 is the current on npm and this module has become unusable by default because of this issue. I don't get how could it get out of beta and published like that.
edit: ok, the usage via old-fashioned script tag and no module system still works, so it's not as bad as I thought at first glance

@dougturnkey
Copy link

Hi! I am a mapbox customer trying to use this tool for a product and I was wondering if this issue will be fixed soon?

@rpadilla6
Copy link

@dougturnkey I wouldn't wait for this to be patched, could take a minute. If you can live with the 1.1.2 version I downgraded to that and got it running without the fs error.

@csimpi
Copy link

csimpi commented Sep 29, 2020

Nothing?

@iacapuca
Copy link

Hey, any hope?

@ilancohen
Copy link

Is there any reason we couldn't just replace the usage of geojsonhint with this:
https://www.npmjs.com/package/geojson-validation

After all, geojsonhint is used in only one place, here:

  api.add = function (geojson) {
    const errors = geojsonhint.hint(geojson, { precisionWarning: false }).filter(e => e.level !== 'message');
    if (errors.length) {
      throw new Error(errors[0].message);
    }

@ericscottmarquez
Copy link

Yeah... why would this get published with this error...

@ericscottmarquez
Copy link

I'm having the same issue with fs as OP stated

@ericscottmarquez
Copy link

ericscottmarquez commented Oct 30, 2020

In reference to #626 (comment),

Doing:

  node: {
    fs: "empty"
  }

(in the webpack config)
really shouldn't be a valid solution...

AliceR added a commit to NASA-IMPACT/admg-casei that referenced this issue Nov 23, 2020
Requires a fix in the webpack config due to mapbox/mapbox-gl-draw#970
@daveisfera
Copy link
Contributor

Any chance we could get this fixed and released?

@neemanjabu
Copy link

For webpack 5 use

//webpack.config.js

module.exports = {
    ...
    resolve: {
        fallback: {
            "fs": false
        },
    }
}

@nrgapple
Copy link

1.1.2 is still giving me the fs error

@ifzm
Copy link

ifzm commented Feb 1, 2021

+1 Can anyone help solve historical problems?

@kknight
Copy link

kknight commented Feb 1, 2021

In case someone is struggling with this; on webpack 5 only the following helped:

resolve: {
    fallback: {
      "fs": false,
      "path": false
    },
}

@arindam1993
Copy link
Contributor

👋 This should now be fixed with v1.2.1

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