Home > Mobile >  How to rename ES Module export to a string literal that is not a valid identifier
How to rename ES Module export to a string literal that is not a valid identifier

Time:12-09

According to the enter image description here

What's wrong and how to make this work?

I've tried importing this in another file like this:

import { "my function" as func} from "./test.js";

console.log(func());

and run this second file with node. Surprisingly, it outputs proper 1. Does this mean that node.js supports this syntax, but TypeScript doesn't?

  • Node v16.15.0
  • TypeScript compiler v4.8.4 (used for checking only, no transpilation)

CodePudding user response:

Using string specifiers for exports is a rather new feature of ES2022.

It is implemented in engines for quite some time and supported by Babel since v7.12, but not yet in TypeScript. There is an open issue which is currently planned for the 4.8 milestone.

CodePudding user response:

Yes indeed.

MDN is about JavaScript, not TypeScript.

NodeJS execute JavaScript too.

  • Related