jfparadis / rollup-esm-test

Test of Rollup with native ESM module

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Test of Rollup with native ESM module

Module support in node is still in early stages (and maybe not ready for runtime), but there are benefits to use it in a tool chain, and to begin creating packages with native support:

  • to get the native behavior of JS in tests
  • to avoid caching issues with esm transpilation

Numerous options are possible as documented here: https://github.com/nodejs/node/blob/master/doc/api/esm.md#approach-1-use-an-es-module-wrapper

Expected Behavior

This form should be usable from a package with native ESM support:

import { rollup } from 'rollup';

As verifiable via a simple command-line test:

node  --input-type=module -e "import { rollup } from 'rollup'; console.log(typeof rollup)"
function

Or as verifiable in context of the test package provided:

git clone https://github.com/jfparadis/rollup-esm-test.git
cd rollup-esm-test
npm install

npm test

# rollup
ok 1 should be equal

1..1
# tests 1
# pass  1

# ok

Actual Behavior

Error, as verifiable via a simple command-line test:

node  --input-type=module -e "import { rollup } from 'rollup';"
import { rollup } from 'rollup';
         ^^^^^^
SyntaxError: The requested module 'rollup' does not provide an export named 'rollup'

Or as verifiable in the context of the test package provided:

git clone https://github.com/jfparadis/rollup-esm-test.git
cd rollup-esm-test
npm install
npm test
import { rollup } from 'rollup';
         ^^^^^^
SyntaxError: The requested module 'rollup' does not provide an export named 'rollup'

Workaround

The workaround is to use a wrapper or an alternate syntax to resolve the exports:

import cjsRollup from 'rollup';
const { rollup } = cjsRollup;

As verifiable via a simple command-line test:

node  --input-type=module -e "import cjsRollup from 'rollup'; const { rollup } = cjsRollup; console.log(typeof rollup)"
function

Or as verifiable the in context of the test package provided, by commenting and uncommenting a few lines in test.js.

About

Test of Rollup with native ESM module

License:Apache License 2.0


Languages

Language:JavaScript 100.0%