URL is not a constructor (esm/commonjs differences)
See original GitHub issueGetting stuck on a really weird webpack/url issue
I have the most simple code (“@ethersproject/providers”: “5.0.0-beta.164”)
import {JsonRpcProvider} from '@ethersproject/providers';
const RPCProvider = new JsonRpcProvider(
`https://xxx`
);
Which fails with (on runtime, not compile time)
TypeError: url__WEBPACK_IMPORTED_MODULE_2__.URL is not a constructor
at geturl.js:60
at Generator.next (<anonymous>)
at geturl.js:8
at new Promise (<anonymous>)
at push.../../node_modules/@ethersproject/web/lib.esm/geturl.js.__awaiter (geturl.js:4)
at getUrl (geturl.js:52)
at index.js:94
at Generator.next (<anonymous>)
at index.js:8
at new Promise (<anonymous>)
at push.../../node_modules/@ethersproject/web/lib.esm/index.js.__awaiter (index.js:4)
at index.js:91
at fetchJson (index.js:140)
at JsonRpcProvider.send (json-rpc-provider.js:273)
at JsonRpcProvider.<anonymous> (json-rpc-provider.js:218)
at Generator.throw (<anonymous>)
at rejected (json-rpc-provider.js:6)
and the corresponding code in geturl is
import { URL } from "url";
const url = new URL(href);
It picks the esm compiled versions, when I check the non esm versions it actually includes URL like so
Totally unclear on why this suddenly started happening though…
Issue Analytics
- State:
- Created 3 years ago
- Comments:13 (7 by maintainers)
Top Results From Across the Web
Uncaught TypeError: URL is not a constructor using WHATWG ...
I faced the same issue, then I looked into the url module and found a solution. For Node V6 use, const URL =...
Read more >TypeError: "x" is not a constructor - JavaScript - MDN Web Docs
The JavaScript exception "is not a constructor" occurs when there was an attempt to use an object or a variable as a constructor,...
Read more >All you need to know to move from CommonJS to ECMAScript ...
We have a lot to cover, so let's jump into it! Enabling ECMAScript modules (ESM) in Node.js; Syntax; Strict by default; Browser compatibility ......
Read more >CommonJS modules | Node.js v19.3.0 Documentation
Modules are cached based on their resolved filename. Since modules may resolve to a different filename based on the location of the calling...
Read more >rollup.js
Importing CommonJS · Publishing ES Modules ... file (see example) --no-esModule Do not add __esModule property --exports <mode> Specify export mode (auto, ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Happy camper here! Sorry for not helping out with the debugging
No worries. All that matters is we found it. 😃
Not sure who to open a bug against upstream though; it’d be nice to help them fix this for future users…