closure-compiler
closure-compiler copied to clipboard
Failing to resolve implied index file when using module_resolution=node
There appears to be an issue with module_resolution=node when using .mjs files.
In my sample project I am unable to get Closure to resolve relative short hand module imports like ../internal to ../internal/index.mjs. As far as I understand, this should be a standard node resolution operation where index is implied if internal is a folder.
If this was my own code I would just change the import to use the long hand notation, but this happens in a third party library (Svelte). As a workaround I have created a SED script for manually rewriting the imports, but it would be great if these types of imports were resolved. Bundlers like Rollup resolve them just fine.
Including relevant parts of my flag file below:
--compilation_level=ADVANCED_OPTIMIZATIONS
--language_out ECMASCRIPT_2015
--language_in ECMASCRIPT_2015
--js_output_file=public/build/bundle-closure.js
--rewrite_polyfills=false
--warning_level=QUIET
--rewrite_polyfills=false
--jscomp_off=checkVars
--package_json_entry_names es2015,module,jsnext:main
--module_resolution=node
--js node_modules/svelte/package.json
--js node_modules/svelte/index.mjs
--js node_modules/svelte/internal/package.json
--js node_modules/svelte/internal/index.mjs
--js node_modules/svelte/store/package.json
--js node_modules/svelte/store/index.mjs
--js node_modules/svelte/transition/package.json
--js node_modules/svelte/transition/index.mjs
--js node_modules/svelte/easing/package.json
--js node_modules/svelte/easing/index.mjs
--js src/**.js
--entry_point=src/main.js
I have a repro of this in my project here: https://github.com/thelgevold/svelte-closure-sample.
Skipping to run the rewrite script (resplace.sh) will reproduce the problem.
Version of Closure: "google-closure-compiler": "20200719.0.0" (npm)
@ChadKillingsworth do you know if this is the expected behavior?
This does indeed look to be a bug. I'm guessing the compiler doesn't look for .mjs extension files at all right now.