JuanCouste / overpass-ql-ts

Overpass QL query builder abstraction with typing
MIT License
5 stars 1 forks source link

`Module not found: Error: Can't resolve 'http'` #19

Open multimeric opened 2 months ago

multimeric commented 2 months ago

My intention is to use the fetch client:

import { FetchOverpassApi, OverpassOutputVerbosity, OverpassFormat, OverpassState } from "overpass-ql-ts";

const api = FetchOverpassApi({

});

However, this fails to compile. My guess is that even having the require("http") anywhere in the module triggers this.

Failed to compile.

Module not found: Error: Can't resolve 'http' in 'node_modules/overpass-ql-ts/lib'
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
        - add a fallback 'resolve.fallback: { "http": require.resolve("stream-http") }'
        - install 'stream-http'
If you don't want to include a polyfill, you can use an empty module like this:
        resolve.fallback: { "http": false }
ERROR in ./node_modules/overpass-ql-ts/lib/esm-bundle.mjs 2446:45-59
Module not found: Error: Can't resolve 'http' in 'node_modules/overpass-ql-ts/lib'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
        - add a fallback 'resolve.fallback: { "http": require.resolve("stream-http") }'
        - install 'stream-http'
If you don't want to include a polyfill, you can use an empty module like this:
        resolve.fallback: { "http": false }

ERROR in ./node_modules/overpass-ql-ts/lib/esm-bundle.mjs 2446:61-76
Module not found: Error: Can't resolve 'https' in 'node_modules/overpass-ql-ts/lib'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
        - add a fallback 'resolve.fallback: { "https": require.resolve("https-browserify") }'
        - install 'https-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
        resolve.fallback: { "https": false }

webpack compiled with 2 errors
Files successfully emitted, waiting for typecheck results...
Issues checking in progress...
JuanCouste commented 2 months ago

Hmph ..., this is not quite ideal, I switched the imports/requires from static to dynamic in order to simplify compatibility between environments ... I guess I'll have to split the files up somehow ... Could you check whether changing require("http") to require(/ webpackIgnore: true / "http"), both http and https should include it. In the meantime consider configuring webpack to ignore http

multimeric commented 2 months ago

Could you check whether changing require("http") to require(/ webpackIgnore: true / "http"),

The only instance I could find was on node_modules/overpass-ql-ts/lib/cjs-bundle.cjs line 2559, which I changed to:

const [http, https] = await Promise.all([Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require(/* webpackIgnore: true */'http')); }), Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require(/* webpackIgnore: true */'https')); })]);

Didn't seem to help though.

In the meantime consider configuring webpack to ignore http

Tricky to do because I'm using Create React App. I'd have to eject to access the config file I think.

multimeric commented 2 months ago

Same with line 2537 of node_modules/overpass-ql-ts/lib/esm-bundle.mjs, which I changed to:

const [http, https] = await Promise.all([import(/* webpackIgnore: true */ 'http'), import(/* webpackIgnore: true */ 'https')]);
JuanCouste commented 2 months ago

Well, since its unlikely that you'd be using the node http adapter, you can comment these lines instead,

static async Load() {
        //const [http, https] = await Promise.all([Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('http')); }), Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('https')); })]);
        //this.Methods = [http.request, https.request];
        this.Loaded = true;
        delete this.LoadPromise;
    }
multimeric commented 2 months ago

Inexplicably, that doesn't work either. It must be caching something somewhere that I don't understand yet.