Search code examples
javascripttypescriptnpmnode-modulescommonjs

"does not contain a default export" even though one is declared


Software rots. I made a minor change to a three year-old GitHub project and the rebuild failed due to automatic security patches. Got everything fixed except for a default import failure.

The error is:

ERROR in ./src/HeatMapTable.js 340:20-27
export 'default' (imported as 'HeatMap') was not found in 'jsheatmap' (module has no exports)

Here's the relevant code:

main.js

import HeatMap, { Style } from "jsheatmap";  //eslint-disable-line no-unused-vars

jhheatmap, index.ts

class Sterno {...}
...
export { Style, Sterno as default }

if I look at what is in node-modules, the jsheatmap/lib/index.js file shows:

var Sterno = /** @class */ (function () {...}
...
exports.default = Sterno;

If I remember my CommonJS correctly, the above export should be compatible with the ECMAScript import used in main.js.

This is my tsconfig.json:

{
    "compilerOptions": {
        "target": "es5",
        "module": "commonjs",
        "lib": [
            "es6",
            "dom"
        ],
        "outDir": "lib",
        "rootDir": "src",
        "strict": true,
        "esModuleInterop": true,
        "resolveJsonModule": true
    },
    "exclude": [
        "test"
    ]
}

package.json


{
  "name": "jsheatmap",
  "version": "1.2.3",
  "description": "Generates heat map data",
  "main": "lib/index.js",
  "type": "module",
  "scripts": {
    "start": "npm run build:live",
    "build": "tsc -p .",
    "build:live": "nodemon --watch 'src/**/*.ts' --exec 'ts-node' src/index.ts",
    "test": "mocha -r ts-node/register test/**/*.ts"
  },...

Solution

  • I successfully deployed your latest commit: https://pokermap.vercel.app/

    • The package-lock.json file makes it possible to use the exact versions of the NPM modules at the time of the commit.
    • Your project seems to be compatible with node 16, but not node 18.

    How to successfully start your project locally:

    git clone https://github.com/JeffML/pokermap.git
    cd pokermap
    npm ci      # Install module versions form package-lock.json
    npm start   # Must be node version 16
    

    How to successfully deploy your project:

    Ensure node version 16 is used:

    • You can modify the package.json engines config.
    • Vercel also allows you to configure the node version via the web settings interface.
    • I believe Netlify deprecated and no longer supports node version 16.