google / google/closure-compiler
Feature Request: Native Node module resolution support
- Dominant language
- JavaScript
- Stars
- 7.7k
- Forks
- 1.2k
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 6
Description
It would be great for Node module resolution to *just work*, without extra arguments.
Right now, you need `--module_resolution NODE` which does nothing unless `--process_common_js_modules` is also passed, and even then, it's shaky. I would confidently say this *doesn't work* in a way that's reasonably accessible (even though I *have* managed to get it to work in the past).
I am not sure what flag I need to tell the compiler to look in `node_modules/`, even when I manually pass in with `--js`. A tale in a few commands:
```shell
$ cat test.js
import { Widget } from 'web-widgets';
console.log(Widget);
```
Execute in Node without issues:
```shell
$ node test.js
[Function: e] {
superClass_: {},
exportStyles: [Function (anonymous)],
from: [Function (anonymous)],
styles: [Getter]
}
```
Check that we definitely have the module installed (hence why the code executes):
```shell
$ ls node_modules/web-widgets/
dist LICENSE package.json README.md
```
Run compiler, complete with flag soup:
```shell
$ google-closure-compiler -O ADVANCED --process_common_js_modules --module_resolution NODE --entry_point test.js test.js
test.js:1: ERROR - [JSC_JS_MODULE_LOAD_WARNING] Failed to load module "web-widgets"
1| import { Widget } from 'web-widgets';
```
????
I feel like this ticket has been opened a thousand times and it ends with @ChadKillingsworth saying you need to pass in `node_modules/` as `--js` arguments as well as `package.json`. I have tried that, and it does not work. it also parses everything in `node_modules/` and dumps a ton of errors. We do not want that. We just want to import the module we are importing.
If I can throw a source file at V8 without issues, I should be able to throw it at the Closure Compiler without issues as well. This is true for everything up until ES6 modules, where everything just breaks down.
Thank you everyone who maintains this tool, it is one of the most important technologies we have in improving the web and I apologize for my frustration. I would be happy to contribute regarding this issue.
Contributor guide
Assessment
This issue has not been assessed yet.