google / google/closure-compiler

Unable to mix ES6 module syntax and goog.provide

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

Description

If you have a file which is has a `goog.provide` at the top, and then attempts to import ES6 module code, the compiler will throw the following exception:

```
[error] something.js:3: variable sum is undeclared
[error] import {sum, pi} from './math/lib';
[error] ^
[error] something.js:3: variable pi is undeclared
[error] import {sum, pi} from './math/lib';
[error] ^
[error] two errors found
```

Removing the `goog.provide` at the top of the file allows this file to compile without errors.

It would be useful to allow existing Closure code to import newer ES6 code.
### Test Files:

`something.js`;

``` js
goog.provide('something');

import {sum, pi} from './math/lib';

console.log(sum(pi, pi));
```

`math/lib.js`;

``` js
export function sum(x, y) {
return x + y;
}

export var pi = 3.14159;
```

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.