Support Node 14's native ES module imports
Currently, @fluent packages are published as type: "commonjs". This means that in Node 14, you can only import then as if they were CommonJS modules:
- From other cjs files:
let {FluentBundle} = require("@fluent/bundle");
let bundle = new FluentBundle();
// Or:
let fluent_bundle = require("@fluent/bundle");
let bundle = new fluent_bundle.FluentBundle();
- From mjs files:
import fluent_bundle from "@fluent/bundle";
let bundle = new fluent_bundle.FluentBundle();
It would be nice to be able to use the following import form, too, just like we can do today in browsers:
import {FluentBundle} from "@fluent/bundle";
let bundle = new FluentBundle();
https://nodejs.org/api/esm.html#esm_dual_commonjs_es_module_packages has a good discussion of the available approaches. I think the most promising would be the wrapper.mjs approach.
I think the packages export all that's needed for both module and commonjs imports, so omitting type should suffice
Seems like Angular 12 is now also having troubles compiling @fluent
./node_modules/@fluent/bundle/esm/index.js:9:0 - Error: Module parse failed: 'import' and 'export' may appear only with 'sourceType: module' (9:0)
File was processed with these loaders:
* ./node_modules/@angular-devkit/build-angular/src/babel/webpack-loader.js
* ./node_modules/@angular-devkit/build-optimizer/src/build-optimizer/webpack-loader.js
* ./node_modules/@ngtools/webpack/src/ivy/index.js
You may need an additional loader to handle the result of these loaders.
| *
| */
> export { FluentBundle } from "./bundle.js";
| export { FluentResource } from "./resource.js";
| export { FluentType, FluentNumber, FluentDateTime } from "./types.js";
hi all! We are a bit low on resources temporarily (most of the focus is on fluent-rs and MessageFormat 2.0 work), so I can't promise when I'll get to this bug.
If anyone can provide a PR, I'll be happy to review and merge it
Webpack 5 fix: https://github.com/projectfluent/fluent.js/pull/556