Bug Report
When running native ESM in Node.js (via .mjs) you are supposed to be able to use an ESM default import to import the module exports of a CJS module:
https://nodejs.org/api/esm.html#esm_interoperability_with_commonjs
Babel will cause the default import to be undefined at runtime in the following situation:
- Your source is ESM being compiled with
@babel/plugin-transform-modules-commonjs.
- The CJS being imported was compiled for distribution using Babel from ESM named exports without a default export. The CJS module exports
__esModule but no default.
Input Code
Input:
// Contains CJS with __esModule, but no default.
import graphql from 'graphql/index.js'
// Should not log undefined.
console.log(graphql.GraphQLSchema)
Flawed output:
"use strict";
var _index = require("graphql/index.js");
var _index2 = _interopRequireDefault(_index);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
console.log(_index2.default.GraphQLSchema);
Expected behavior/code
At runtime, GraphQLSchema should log instead of undefined.
Babel Configuration (.babelrc, package.json, cli command)
Default usage of @babel/plugin-transform-modules-commonjs or @babel/preset-env.
Environment
- Babel version(s): v7.0.0-beta.47
- Node/npm version: Node v10.1.0/npm v6.0.1
- OS: [e.g. OSX 10.13.4, Windows 10]
- Monorepo: No
- How you are using Babel:
cli
Possible Solution
Additional context/Screenshots
The example input demonstrates a workaround to graphql/express-graphql#425.
Bug Report
When running native ESM in Node.js (via
.mjs) you are supposed to be able to use an ESM default import to import the module exports of a CJS module:https://nodejs.org/api/esm.html#esm_interoperability_with_commonjs
Babel will cause the default import to be
undefinedat runtime in the following situation:@babel/plugin-transform-modules-commonjs.__esModulebut nodefault.Input Code
Input:
Flawed output:
Expected behavior/code
At runtime,
GraphQLSchemashould log instead ofundefined.Babel Configuration (.babelrc, package.json, cli command)
Default usage of
@babel/plugin-transform-modules-commonjsor@babel/preset-env.Environment
cliPossible Solution
Additional context/Screenshots
The example input demonstrates a workaround to graphql/express-graphql#425.