- 
                Notifications
    
You must be signed in to change notification settings  - Fork 5.8k
 
fix(bundle): allow importing json with import attributes inside npm packages #30265
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
Conversation
| 
           I think that it needs to be only for require, not imports. It's a little tricky for bundle specifically, because this check happens at module load time, but we only directly know whether it's an import/require in the resolve hook. So I think we need to either add a check at resolve time and disable the one at load, or store the import kind in the resolve hook and somehow associate that with a later load  | 
    
| && !self.in_npm_pkg_checker.in_npm_package(specifier) | ||
| && !matches!(requested_module_type, RequestedModuleType::Json) | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe swap these? The in_npm_package check is more expensive.
That said, we should probably make this work even when using cjs outside npm packages and also we still want to surface this error for ESM in npm packages as Nathan mentioned.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should push this error up into the module loader in the CLI and just not bother surfacing it for bundle? Ideally esbuild would handle doing this error for us.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Esbuild just allows importing json without an attribute, as do all other bundlers I'm aware of
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would be in favor of just not erroring at all for bundle, but there's also #30114 which indicates some people want the behavior to align with runtime
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should just not error and close as won’t fix. Probably not worth the effort or added complexity. I’m not sure that pr fully fixes it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As for #30114, it may be okay for deno bundle to accept a wider range of code than plain deno, but not the other way round. For example, if plain deno accepts an npm module, so should deno bundle.
In other words, #30265 (comment) would be okay.
| 
           I am wondering which way this will go. I see three ways: 
 Option 1 is ideal. But if that's not feasible, option 2 seems more useful since it: 
 I believe this PR chooses option 2.  | 
    
          
 The team discussed this, and we decided we’re going to accept JSON imports without the attribute in deno bundle, but not allow it in deno run. I’ll do a PR this coming week.  | 
    
| 
           Closing in favor of #30413  | 
    
Running
deno bundleon an npm module that imports or requires.jsonfiles should work and not error. This PR updates our "check if import attribute is present" logic to exclude files coming from inside npm packages.Fixes #30263