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

Deno 1.9.0, Uncaught InvalidData: invalid url scheme #955

Closed
FSou1 opened this issue Apr 13, 2021 · 7 comments · Fixed by #997
Closed

Deno 1.9.0, Uncaught InvalidData: invalid url scheme #955

FSou1 opened this issue Apr 13, 2021 · 7 comments · Fixed by #997
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@FSou1
Copy link
Contributor

FSou1 commented Apr 13, 2021

I have recently published a module: https://deno.land/x/fsquery/mod.ts

It works locally and at github actions.

Now I'm trying to test it:

import { fsselect } from 'https://deno.land/x/fsquery@deno-module-0.1/mod.ts';

await fsselect("select * from .");

Unfortunately, I have been receiving the error:

error: Uncaught InvalidData: invalid url scheme
    throw new Deno.errors.InvalidData("invalid url scheme");
          ^
    at fileURLToPath (https://deno.land/std@0.92.0/node/url.ts:53:11)
    at createRequire (https://deno.land/std@0.92.0/node/module.ts:535:18)
    at https://deno.land/x/fsquery@deno-module-0.1/parser.ts:3:17

Here is a tricky point, which actually causes this error:

import { createRequire } from "./deps.ts";
const require = createRequire(import.meta.url);
const parser = require("./peg-parser.js");
export default parser;

Update: I've changed the module declaration from CommonJS to ES6 module. The issue is resolved now, but still reproducible at the fsquery@deno-module-0.1 version.

@lucacasonato
Copy link
Member

createRequire can only be used from file modules. We should improve the error message here.

@lucacasonato lucacasonato transferred this issue from denoland/deno Jun 8, 2021
@lucacasonato lucacasonato added bug Something isn't working good first issue Good for newcomers labels Jun 8, 2021
@TotallyNotChase
Copy link
Contributor

@lucacasonato I'd like to take this on. What do you think the error message here should be? I think, ideally, it should highlight that the filename url should be of file protocol. But it could also include a note about how createRequire is expected to be used from file modules (though this note is only relevant when the passed argument is import.meta.url)

@lucacasonato
Copy link
Member

Probably something along the lines of createRequire only supports 'file://' URLs would be enough.

@Haprog
Copy link

Haprog commented Jul 10, 2022

It seems like the old error message is still being used for this even in Deno 1.23.3. I ran into this when trying to use:

import { create } from 'https://deno.land/x/deno_exif@0.0.2/mod.ts';

createRequire can only be used from file modules. We should improve the error message here.

First few times I was reading this I wasn't even sure what this means. First I thought what even is a "file module"? And what is the case that is not working/supported then?

Do I understand it correctly now that createRequire does not work for importing via HTTP/HTTPS URLs?

If so, this should definitely be clarified in the documentation (at least here and here).

Basically any code that uses createRequire for example:

const require = createRequire(import.meta.url);
const something = require("./something");

does not work when imported via HTTP/HTTPS URLs.

@kt3k
Copy link
Member

kt3k commented Jul 11, 2022

@Haprog Thanks for reporting. deno_exif depends on deno_std@0.88.0, but the error message was fixed at deno_std@0.101.0. So deno_exif needs to update the std version to get the better error message

@Haprog
Copy link

Haprog commented Jul 11, 2022

@kt3k Right, thanks for pointing that out. I did do some tests updating it locally to use latest version of std but I didn't realize to check the error message using that.

Looks like with std@0.147.0 the error is:

error: Uncaught TypeError: The URL must be of scheme file
    throw new ERR_INVALID_URL_SCHEME("file");

which is slightly better I guess, but imo it's still not very clear (from the error) what is the issue in this kind of usage context.

Should I open a new issue about improving the documentation (related to links to docs I posted above)?

@kt3k
Copy link
Member

kt3k commented Jul 13, 2022

@Haprog Thanks for reporting. Right, the error message doesn't look great now. I opened #2440 to try to address this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
5 participants