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

SyntaxError: Cannot use import statement outside a module #26

Open
ajubin opened this issue Jan 30, 2023 · 2 comments · May be fixed by #30
Open

SyntaxError: Cannot use import statement outside a module #26

ajubin opened this issue Jan 30, 2023 · 2 comments · May be fixed by #30

Comments

@ajubin
Copy link

ajubin commented Jan 30, 2023

Hi,

When running jest, I've got the following error SyntaxError: Cannot use import statement outside a module , I don't know how to avoid it

@ajubin
Copy link
Author

ajubin commented Jan 30, 2023

Here's my jest.config.js file

// For a detailed explanation regarding each configuration property, visit:
// https://jestjs.io/docs/en/configuration.html

module.exports = {
  moduleFileExtensions: ['js', 'json', 'jsx', 'ts', 'tsx', 'node'],
  moduleNameMapper: {
    '@src/(.*)': '<rootDir>/src/$1',
    '\\.(css|less|scss|sss|styl)$': '<rootDir>/node_modules/jest-css-modules',
  },
  roots: ['<rootDir>/src'],
  transform: {
    '\\.tsx?$': 'ts-jest',
  },
};

I've tried most of the solutions here https://stackoverflow.com/questions/58613492/how-to-resolve-cannot-use-import-statement-outside-a-module-in-jest but none of them are working.

I don't know how I can solve this

@Ricki-BumbleDev
Copy link

Same here. I think it is because the package.json is missing "type": "module". I will create a pull request.

@Ricki-BumbleDev Ricki-BumbleDev linked a pull request Nov 7, 2023 that will close this issue
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 a pull request may close this issue.

2 participants