Skip to content
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

How to use .cjs extension for config when using "module" type in package.json #169

Open
paul-uz opened this issue Aug 11, 2022 · 2 comments

Comments

@paul-uz
Copy link

paul-uz commented Aug 11, 2022

I'm trying to move a load of Lambda functions to MJS, so I have set the type to "module" in package.json.

However, this means the jest-dynamodb-config.js gets interpreted as a module file, buts its commonjs.

I tried changing jest-dynamodb-config.js to jest-dynamodb-config.cjs but it fails with the following:

Error: Jest: Got error running globalSetup - /Users/me/Programming/Work/myproject/node_modules/@shelf/jest-dynamodb/setup.js, reason: Cannot find module '/Users/me/Programming/Work/myproject/jest-dynamodb-config.js'
@brucelay
Copy link

Had the same issue, it's covered in the README. My solution:

jest.config.cjs

const {resolve} = require('path');

process.env.JEST_DYNAMODB_CONFIG = resolve(__dirname, './jest-dynamodb-config.cjs');

module.exports = {
  "preset": "@shelf/jest-dynamodb"
}

@paul-uz
Copy link
Author

paul-uz commented Feb 7, 2024

@brucelay that does work, but in the README, the solution description doesn't mention anything about ESM, modules, mjs etc

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

No branches or pull requests

2 participants