Skip to content

fix: Library couldn't be imported as ES module #92

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 31, 2023
Merged

Conversation

jimmycallin
Copy link
Contributor

  • I have added automatic tests where applicable
  • The PR title is suitable as a release note
  • The PR contains a description of what has been changed
  • The description contains manual test instructions

Changes

Without setting type: "module", the library couldn't be imported as es module. This caused it to throw the following error when trying to import { Session } from an ES module:

SyntaxError: Named export 'Session' not found. The requested module '@ftrack/api' is a CommonJS module, which may not support all module.exports as named exports.

By changing the name of the umd package to use cjs file ending, it is still working properly as a CJS module as well, not causing any breaking changes.

Test

Try to import it in both a CJS and ESM setting, making sure it's working as expected in both.

Example:

test.mjs:

import { Session } from "@ftrack/api";

test.cjs:

const { Session } = require("@ftrack/api");

@jimmycallin jimmycallin requested a review from a team as a code owner March 30, 2023 20:57
@jimmycallin jimmycallin requested a review from gismya March 30, 2023 20:57
@jimmycallin jimmycallin merged commit 872ccca into main Mar 31, 2023
@jimmycallin jimmycallin deleted the type-module branch March 31, 2023 07:15
gismya pushed a commit to gismya/ftrack-javascript that referenced this pull request Apr 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants