Closed muellerberndt closed 5 years ago
Just found this StackOverflow answer. Maybe the URL variable is overwritten somewhere?
I also tried this code in the browser (it works):
<html>
<head>
<script>
var URL
URL = URL || require('url').URL
var url = new URL("https://www.google.com");
console.log(url);
</script>
Also, for reference, this is the context where I'm getting the exception:
@nbanmp is this code necessary?
var URL
URL = URL || require('url').URL
This is what seems to break the remix-ide, it works when removed.
@b-mueller my guess is that you need:
var URL
URL = (typeof window !== 'undefined' && window.URL)
? window.URL : require('url').URL
Yep, that works.
Here is an example of this error occurring.
1) In the first file Twilio.js
(name not important) an attempt is made to call the URL
class from the url
library
( var url = require ('url');
).
2) The second file url.d.ts
(which stores types for the url
library) has a description for the URL
class.
So when you write new url.Url
linter does not swear, because the class being called is described in the typing.
This usually means that the library has similar functionality.
... but not this time ...
3) In the third file url.js
(where the basic logic for the url
library is described) the URL
class is missing.
And this is why the error occurs. As a result, the url.URL
is not a constructor or function or anything else.
It's just undefined
.
P.S.:
Twilio.js
(is a case from my problem, but it shows a General problem).This work for me:
Change this:
var URL = window.URL;
By this:
function URL(url, base) {
this.url = url;
this.base = base;
return window.URL;
}
on file node_modules/recordrtc/RecordRTC.js
I did with that script on package
"postinstall": "cp patch/RecordRTC.js node_modules/recordrtc/RecordRTC.js"
tested with angular 14 SSR, you should lazy load it to prevent it leak to override global namespace URL of nodejs (mention here https://github.com/muaz-khan/RecordRTC/issues/666)
dont have to hack in node_modules
let RecordRTC;
let moduleRecord;
await this.ngZone.run(async () => {
// https://stackoverflow.com/a/58859327/5748537
moduleRecord = await import('recordrtc');
RecordRTC = (moduleRecord as any).default;
});
this.record = new RecordRTC(this.stream, {
mimeType: 'audio/wav',
type: 'audio',
numberOfAudioChannels: 1,
disableLogs: true,
desiredSampRate: 12000,
recorderType: RecordRTC.StereoAudioRecorder,
});
do you love me?
After #104, armlet still errors in the browser at the same line as before:
This time the error is:
Which is surprising because URL is supposed to be a built-in class and I'm convinced I had it working exactly like that. Tested in Safari and Chrome.