closure-compiler icon indicating copy to clipboard operation
closure-compiler copied to clipboard

Absolute imports do not auto resolve to index.js files in node resolution mode

Open khanguy00 opened this issue 5 years ago • 3 comments

Affects:

Version: v20200927.0.0
Built on: 2020-09-29 11:30

Inputs:

// main.js
import { A } from 'foo';
console.log(A);

// foo/index.js
export const A = 'B';

Command:

java -jar compiler.jar -O ADVANCED --language_out ECMASCRIPT_2017 --module_resolution NODE --js main.js --js foo/index.js

Errors:

main.js:1:0: ERROR - [JSC_JS_MODULE_LOAD_WARNING] Failed to load module "foo"
  1| import { A } from 'foo';
     ^

Expected output: No error

Notes: Relative imports (import { A } from './foo') works as expected, outputs:

'use strict';console.log("B");

khanguy00 avatar Sep 29 '20 01:09 khanguy00

Thanks for the report.

blickly avatar Sep 30 '20 00:09 blickly

Just want to confirm: Is this a bug or a feature?

Since the doc here said Modules which do not begin with a "." or "/" character are looked up from the appropriate node_modules folder, while the Node resolution supports this import behavior.

khanguy00 avatar Sep 30 '20 09:09 khanguy00

Added Chad in case he has an opinion.

blickly avatar Sep 30 '20 18:09 blickly