Skip to content

import.meta syntax error message needs work #336

@DerekNonGeneric

Description

@DerekNonGeneric

What's the issue?

The syntax error message for import.meta is worse than google-closure-compiler — provides misleading line number and does not specify exactly what went wrong.

Take the following code sample and attempt to compile it.

import { createRequire } from 'module';
const require = createRequire(import.meta.url);
export default require;

rollup-plugin-closure-compiler outputs the following error, which is misleading.

[!] (plugin closure-compiler) SyntaxError: Unexpected token (3:36)
undefined (3:36)
SyntaxError: Unexpected token (3:36)
    at Parser.pp$4.raise [...]
  • 💭 What token was unexpected?
  • 💭 The "syntax error" occurred on line 2, yet it reports line 3?

google-closure-compiler outputs the following error, which is crystal-clear.

ERROR - [JSC_CANNOT_CONVERT] This code cannot be converted from ES6. import.meta
const require = createRequire(import.meta.url);
                              ^^^^^^^^^^^

1 error(s), 0 warning(s)

How do we reproduce the issue?

Surely some of this is superfluous, but here's my configuration.

  plugins: [
    compiler({
      compilation_level: 'ADVANCED_OPTIMIZATIONS',
      warning_level: 'VERBOSE',
      checks_only: true,
      jscomp_error: 'strictCheckTypes',
      jscomp_off: [
        'moduleLoad',
        'undefinedVars',
      ],
      language_in: 'ES_NEXT',
      language_out: 'ECMASCRIPT_NEXT',
      module_resolution: 'node',
      process_common_js_modules: true,
      extra_annotation_name: ['flag'],
    }),
  ],

Thanks in advance for any effort towards correcting this!

Metadata

Metadata

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions