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

Jest Testing Error #34

Closed
TerryCaliendo-WealthCounsel opened this issue Apr 24, 2023 · 3 comments
Closed

Jest Testing Error #34

TerryCaliendo-WealthCounsel opened this issue Apr 24, 2023 · 3 comments

Comments

@TerryCaliendo-WealthCounsel

Thanks for writing this package!

I'm getting the following error in Jest when tying to use this package. It looks like the issue may be because the 'irregular-plurals' dependency uses a "require" instead of "import" (even thought the error says "SyntaxError: Cannot use import statement outside a module", it's pointing to the "require" statement)

`Test suite failed to run

Jest encountered an unexpected token

Jest failed to parse a file. This happens e.g. when your code or its dependencies use non-standard JavaScript syntax, or when Jest is not configured to support such syntax.

Out of the box Jest supports Babel, which will be used to transform your files into valid JS based on your Babel configuration.

By default "node_modules" folder is ignored by transformers.

Here's what you can do:
 • If you are trying to use ECMAScript Modules, see https://jestjs.io/docs/ecmascript-modules for how to enable it.
 • If you are trying to use TypeScript, see https://jestjs.io/docs/getting-started#using-typescript
 • To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
 • If you need a custom transformation specify a "transform" option in your config.
 • If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.

You'll find more details and examples of these config options in the docs:
https://jestjs.io/docs/configuration
For information about custom transformations, see:
https://jestjs.io/docs/code-transformation

Details:

C:\Repos\wb-vue\node_modules\plur\index.js:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,jest){import irregularPlurals from 'irregular-plurals';
                                                                                  ^^^^^^

SyntaxError: Cannot use import statement outside a module

> 1 | import plur from 'plur'
    | ^
  2 | 
  3 |
  4 | import EpmlFnReturnType from '../classes/EpmlFnReturnType'

  at Runtime.createScriptFromCode (node_modules/jest-runtime/build/index.js:1728:14)
  at Object.<anonymous> (src/plugins/epml-interpreter/epml/plural.js:1:1)
  at Object.<anonymous> (tests/unit/src/plugins/epml-interpreter/epml/plural.test.js:2:1)
  at TestScheduler.scheduleTests (node_modules/@jest/core/build/TestScheduler.js:333:13)
  at runJest (node_modules/@jest/core/build/runJest.js:404:19)
  at _run10000 (node_modules/@jest/core/build/cli/index.js:320:7)
  at runCLI (node_modules/@jest/core/build/cli/index.js:173:3)
@sindresorhus
Copy link
Owner

This is a problem with your Jest config, not this package

https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c

@sindresorhus sindresorhus closed this as not planned Won't fix, can't repro, duplicate, stale Apr 24, 2023
@TerryCaliendo-WealthCounsel
Copy link
Author

Thanks for the quick response... for anyone else that may come across this I had to add to my Jest config

module.exports = {
    transformIgnorePatterns: [
        'node_modules/(?!(plur)/)',
    ],
}

@sindresorhus ... can this package detect if a word is already plural? I was going to use your package because its smaller than "puralize" but not having "extra" functionality may be why it its smaller.

@sindresorhus
Copy link
Owner

No, it does not have such functionality.

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

No branches or pull requests

2 participants