Skip to content

ReferenceError: exports is not defined in ES module scope #310

@the-other-dev

Description

@the-other-dev

When upgrading from version 1.4.5 to 1.5.0 I get an error when trying to import the module.

I am using import cron from 'cron-validate' to import the module. My project is set up as a module ("type": "module" in the package.json) and my tsconfig.json sets the following things:

        "target": "ESNext",
        "lib": ["ES2019", "DOM"],
        "module": "ESNext",
        "moduleResolution": "node",
        "esModuleInterop": true,

The full error message is:

ReferenceError: exports is not defined in ES module scope
This file is being treated as an ES module because it has a '.js' file extension and './node_modules/cron-validate/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
 ❯ node_modules/cron-validate/lib/index.js:5:23

I assume it has something to do with the tsconfig.json in this repository declaring "module": "commonjs" (https://github.com/Airfooox/cron-validate/blob/master/tsconfig.json#L8) and declaring it a module in the package.json: https://github.com/Airfooox/cron-validate/blob/master/package.json#L38

The change to "type": "module" came with this commit: 532fedb

In version 1.4.5 the import works without issues.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions