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

feat(cli): better error message when failed to resolve non explicit CJS module from ESM #26802

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Hajime-san
Copy link
Contributor

Summary

part of

I think it covers almost use cases, while it's not as strict as the Node.js implementation.

Changes

  • app.tsx
import ReactDomServer from 'npm:[email protected]/server'
console.log(ReactDomServer);

before

% deno run app.tsx
error: Unable to load /path/to/Library/Caches/deno/npm/registry.npmjs.org/react-dom/16.8.5/server imported from file:///path/to/app.tsx

Caused by:
    No such file or directory (os error 2)

after

% /path/to/deno/target/debug/deno run app.tsx
error: Unable to load /path/to/Library/Caches/deno/npm/registry.npmjs.org/react-dom/16.8.5/server imported from file:///path/to/app.tsx
Did you mean to import "npm:[email protected]/server.js"?

Caused by:
    No such file or directory (os error 2)

@Hajime-san Hajime-san force-pushed the show-suggestion-for-cjs branch 2 times, most recently from 558f00f to 5e95117 Compare November 10, 2024 05:30
Comment on lines +548 to +563
pub fn get_raw_speficier(
&self,
specifier: &ModuleSpecifier,
) -> Option<Ref<'_, Url, String>> {
self.raw_specifier.get(specifier)
}

pub fn set_raw_speficier(
&self,
specifier: &ModuleSpecifier,
raw_specifier: &str,
) {
self
.raw_specifier
.insert(specifier.clone(), raw_specifier.to_string());
}
Copy link
Contributor Author

@Hajime-san Hajime-san Nov 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I remove the map when the module succeed to load as same as below?

/// Frees the parsed source from memory.
pub fn free(&self, specifier: &ModuleSpecifier) {
self.sources.lock().remove(specifier);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant