Skip to content

Support Node 14's native ES module imports #482

Open

Description

@stasm

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();

Activity

  1. changed the title [-]Support Node 14's native ES module[/-] [+]Support Node 14's native ES module imports[/+] on May 5, 2020
  2. stasm commented on May 5, 2020

    @stasm
    ContributorAuthor

    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.

  3. ranisalt commented on Apr 27, 2021

    @ranisalt
    Contributor

    I think the packages export all that's needed for both module and commonjs imports, so omitting type should suffice

  4. tobias47n9e commented on May 14, 2021

    @tobias47n9e

    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";
    
  5. zbraniecki commented on May 16, 2021

    @zbraniecki
    Collaborator

    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

  6. Demivan commented on May 28, 2021

    @Demivan
    Contributor

    Webpack 5 fix: #556

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions