Skip to content
This repository was archived by the owner on May 23, 2023. It is now read-only.
This repository was archived by the owner on May 23, 2023. It is now read-only.

__esModule is true while no default export provided, breaks interoperability #145

@sdavids

Description

@sdavids

opentracing-javascript does not work with NodeJS in experimental-modules mode when webpack is involved.

test.js

import opentracing from 'opentracing';

console.log(opentracing.globalTracer());

webpack.config.cjs

const path = require('path');
const nodeExternals = require('webpack-node-externals');

module.exports = {
  mode: 'production',
  target: 'node',
  externals: nodeExternals(),
  entry: path.resolve(__dirname, 'test.js'),
  output: {
    filename: 'bundle.js',
    path: path.resolve(__dirname),
    publicPath: '/',
  },
};

package.json

{
  "name": "opentracing-example",
  "private": true,
  "type": "module",
  "scripts": {
    "build": "webpack --config webpack.config.cjs && mv dist/bundle.js dist/bundle.cjs",
  },
  "dependencies": {
    "opentracing": "~0.14.4"
  },
  "devDependencies": {
    "webpack": "~4.42.0",
    "webpack-cli": "~3.3.11",
    "webpack-node-externals": "~1.7.2"
  }
}
$ node --experimental-modules test.js
(node:86152) ExperimentalWarning: The ESM module loader is experimental.
GlobalTracerDelegate {}
$ node bundle.cjs
...
TypeError: Cannot read property 'globalTracer' of undefined
...

The culprit in bundle.cjs is the following:

    var r = e && e.__esModule ? function () {
      return e.default
    } : function () {
      return e
    };

Due to opentracing/lib/index.js having

Object.defineProperty(exports, "__esModule", { value: true });

It tries to load the default export which does not exist.

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