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

Friendly error message when importing node built-in modules without a node: prefix #17493

Closed
dsherret opened this issue Jan 22, 2023 · 3 comments · Fixed by #17519
Closed

Friendly error message when importing node built-in modules without a node: prefix #17493

dsherret opened this issue Jan 22, 2023 · 3 comments · Fixed by #17519
Labels
suggestion suggestions for new features (yet to be agreed)

Comments

@dsherret
Copy link
Member

dsherret commented Jan 22, 2023

This depends on support for node: modules in #16223

When built-in Node.js modules are imported without node: prefix a friendly error message is shown:

import { readFile } from "fs";
Add a "node:" prefix to the following import:
  import { readFile } from "fs";
Like this:
  import { readFile } from "node:fs";

This is only relevant to the user code - dependencies imported with npm: specifiers will have these modules available in both forms.

@dsherret dsherret added the suggestion suggestions for new features (yet to be agreed) label Jan 22, 2023
@aapoalas
Copy link
Collaborator

This should probably be an LSP FixIt as well.

@dsherret dsherret mentioned this issue Jan 22, 2023
13 tasks
@albnnc
Copy link
Contributor

albnnc commented Jan 22, 2023

Continuing roadmap discussion, is this going to support searching in different URI scopes like deno: or custom: (in case they are going to be implemented)?


Currently, we have the following behaviour:

➜  ~ deno repl -A
Deno 1.29.4
exit using ctrl+d, ctrl+c, or close()
> import * as fs from "fs"
Uncaught TypeError: Relative import path "fs" not prefixed with / or ./ or ../ from "file:///Users/albnnc/$deno$repl.ts"
    at async :2:12
>

What about unbiased message like "Hey, we got bare specifier, do you want to add import map entry?"? This would advocate Node less, which is good, in my opinion.

@dsherret
Copy link
Member Author

Continuing roadmap discussion, is this going to support searching in different URI scopes like deno: or custom: (in case they are going to be implemented)?

Not for this issue. This is just for known node built-in modules like "fs" -> "node:fs" in order to help guide people on how to run Node code in Deno. This is instead of supporting bare specifiers like "fs", which would not be great IMO.

What about unbiased message like "Hey, we got bare specifier, do you want to add import map entry?"? This would advocate Node less, which is good, in my opinion.

I think this should be more explanatory for any import that matches a node built-in module's bare specifier since it would be more helpful to give Node users a clear path to getting their existing code running in Deno. Obviously we'd like users not to use node: imports, but some people might have a lot of existing code using that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
suggestion suggestions for new features (yet to be agreed)
Projects
None yet
3 participants