ES6 Module Transpiler NPM Resolver
raw JSON →A resolver extension for es6-module-transpiler (v0.10+) that enables importing ES6 modules from npm packages using the jsnext:main flag. This package bridges npm resolution with ES6 module transpilation, allowing developers to import modules by package name (e.g., 'import foo from "foo"') instead of brittle relative paths into node_modules. Active development ceased; the last release v0.3.0 dates from 2016 and the ecosystem has moved to native ES modules or newer transpilers (Babel, TypeScript). Key differentiator: it was the first solution to integrate npm package resolution into the es6-module-transpiler pipeline via a custom resolver class, relying on the jsnext:main convention popularized by libraries like Rollup. Requires es6-module-transpiler as a peer dependency.
Common errors
error Error: Cannot find module 'es6-module-transpiler' ↓
error TypeError: NPMFileResolver is not a constructor ↓
error Error: Module 'foo' not found ↓
Warnings
deprecated Package is no longer maintained; no updates since 2016. ↓
gotcha The resolver only works with packages that have a jsnext:main field in package.json; otherwise it throws a lookup error. ↓
gotcha This resolver does NOT provide interoperability between ES6 modules and CommonJS modules. It only resolves ES6 source files within npm packages. ↓
breaking v0.3.0 requires es6-module-transpiler >=0.10.0. Using an older version of the transpiler will cause resolution failures. ↓
Install
npm install es6-module-transpiler-npm-resolver yarn add es6-module-transpiler-npm-resolver pnpm add es6-module-transpiler-npm-resolver Imports
- default wrong
const NPMFileResolver = require('es6-module-transpiler-npm-resolver').defaultcorrectimport NPMFileResolver from 'es6-module-transpiler-npm-resolver' - NPMFileResolver wrong
const NPMFileResolver = require('es6-module-transpiler-npm-resolver').NPMFileResolvercorrectconst NPMFileResolver = require('es6-module-transpiler-npm-resolver'); - Container wrong
const Container = require('es6-module-transpiler').Container;correctconst { Container } = require('es6-module-transpiler');
Quickstart
const transpiler = require('es6-module-transpiler');
const Container = transpiler.Container;
const FileResolver = transpiler.FileResolver;
const NPMFileResolver = require('es6-module-transpiler-npm-resolver');
const formatters = require('es6-module-transpiler/lib/formatters');
const Formatter = formatters[formatters.DEFAULT];
const container = new Container({
resolvers: [
new FileResolver(['lib/']),
new NPMFileResolver([process.cwd()])
],
formatter: new Formatter()
});
container.getModule('index');
container.write('out/mylib.js');
console.log('Build complete.');