Skip to content

ESM loader cannot find a module detected by rollup #2081

@pravi

Description

@pravi
  • Version: v12.7
  • Platform: linux
  • Subsystem:

With the following test code (test.mjs),

import { encode } from 'sourcemap-codec';
 console.log(encode);

And rollup.config.js

import resolve from 'rollup-plugin-node-resolve';
const plugins = [ resolve(), ];
export default [                                        /* umd */                                       
{                                                       input: 'test.mjs',                              
plugins,                                        
output: {                                               
file: 'bundle.js',                              
format: 'umd',                                  
name: 'Test',                                   
sourcemap: true                         
}
        
}
];

Run npm install sourcemap-codec

Then rollup -c

test.mjs → bundle.js...

created bundle.js in 41ms

There are no warnings and

$ node bundle.js
[Function: encode]
$

But

$ node --experimental-modules test.mjs                   
(node:26761) ExperimentalWarning: The ESM module loader is experimental.
file:///home/praveen/forge/test-rollup/test.mjs:1

import { encode } from 'sourcemap-codec';
         ^^^^^^                                 SyntaxError: 
The requested module 'sourcemap-codec' 
does not provide an export named 'encode'
 
   at ModuleJob._instantiate 
(internal/modules/esm/module_job.js:93:21)                          
  at async ModuleJob.run 
(internal/modules/esm/module_job.js:108:20)                             
 at async Loader.import 
(internal/modules/esm/loader.js:134:24)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions