google / google/closure-compiler

Allow import from absolute URLs (or passthrough import mode)

Open
#3,708 2 comments 3 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
7.7k
Forks
1.2k
Avg merge
2d 12h
Merged PRs (30d)
6

Description

Closure Compiler rejects import statements from an absolute URL. This should be easy to support if it just passes them through verbatim. Instead any presence of such a line causes the entire script to fail to compile.

Example in.js:

```js
import test from "https://cdn.example.com/test.js";
```

Command line:
`java -jar ./closure-compiler.jar --js in.js --js_output_file out.js --compilation_level SIMPLE --language_in ECMASCRIPT_2020 --language_out ECMASCRIPT_2020`

Observed result:
```
in.js:2:0: ERROR - [JSC_INVALID_MODULE_PATH] Invalid module path "https://cdn.example.com/test.js" for resolution mode "BROWSER"
2| import test from "https://cdn.example.com/test.js";
^

1 error(s), 0 warning(s)
```

Expected result:

Output file to contain the same import statement.

Similar to issue #3707, if there is a passthrough module resolution mode, we can just set it to output import statements verbatim and this case will work. This makes it much easier to use Closure Compiler as a general minifier tool, since otherwise the presence of module features causes the whole compilation to fail.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.