google / google/closure-compiler

require with a substitution-free template string is not recognized by process_common_js_modules

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

Description

I'm using the compiler with the `process_common_js` option set to `true`.

The following code works fine:

```javascript
/** @const */
const update = require( "./update.js" );
```

However, switching to a substitution-free template string breaks:

```javascript
/** @const */
const update = require( `./update.js` );
```

resulting in:

```
src/main.js:8: ERROR - variable require is undeclared
const update = require( `./update.js` );
^^^^^^^
```

The code style of the project I'm working on imposes template strings wherever syntactically possible (only object keys get a pass and can use double quotes). Of course, this does include paths in `require` statements. Sadly, it seems the CommonJS machinery does not recognize such statements as processable.

As a workaround, I can break from the code style but it is clearly not ideal and it would be really nice if the compiler was able to handle this.

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.