Skip to content

dbt commands fail with SyntaxError: Cannot use import statement outside a module #406

Description

@anandgupta42

Description

All dbt commands fail when running via the installed npm package (v0.5.3+):

(node:13840) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
/Users/.../@altimateai/altimate-code/dbt-tools/dist/index.js:1
import { createRequire } from "node:module";
^^^^^^
SyntaxError: Cannot use import statement outside a module

Root Cause

publish.ts copies dbt-tools/bin/ and dbt-tools/dist/ into the published package but does not include a package.json with "type": "module". Without it, Node treats .js files as CJS and chokes on ESM import statements.

The bug was not caught because Bun (used for development/testing) handles ESM natively without needing "type": "module".

Affected Versions

Workaround

echo '{"type":"module"}' > $(npm root -g)/@altimateai/altimate-code/dbt-tools/package.json

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions