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

Warning in project that is not used styled-components #15

Closed
nvh95 opened this issue Apr 4, 2022 · 0 comments · Fixed by #17
Closed

Warning in project that is not used styled-components #15

nvh95 opened this issue Apr 4, 2022 · 0 comments · Fixed by #17
Labels
bug Something isn't working

Comments

@nvh95
Copy link
Owner

nvh95 commented Apr 4, 2022

When running jest at project that doesn't use styled-components. Following warnings are emitted.

(node:2000) UnhandledPromiseRejectionWarning: Error: Cannot find module 'styled-components' from 'node_modules/jest-preview/dist/styled-components.js'

Require stack:
  node_modules/jest-preview/dist/styled-components.js
  node_modules/jest-preview/dist/index.js
  src/__tests__/App.test.tsx


However, Jest was able to find:
	'./styled-components.d.ts'
	'./styled-components.js'

You might want to include a file extension in your import, or update your 'moduleFileExtensions', which is currently ['tsx', 'ts', 'web.js', 'js', 'web.ts', 'web.tsx', 'json', 'web.jsx', 'jsx', 'node'].

See https://jestjs.io/docs/configuration#modulefileextensions-arraystring
    at Resolver.resolveModule (/vitejs-vite-hlfd63/node_modules/jest-resolve/build/resolver.js:324:11)
    at Resolver._getVirtualMockPath (/vitejs-vite-hlfd63/node_modules/jest-resolve/build/resolver.js:471:14)
    at Resolver._getAbsolutePath (/vitejs-vite-hlfd63/node_modules/jest-resolve/build/resolver.js:457:14)
    at Resolver.getModuleID (/vitejs-vite-hlfd63/node_modules/jest-resolve/build/resolver.js:424:31)
    at Runtime._shouldMock (/vitejs-vite-hlfd63/node_modules/jest-runtime/build/index.js:1917:37)
    at Runtime.requireModuleOrMock (/vitejs-vite-hlfd63/node_modules/jest-runtime/build/index.js:1204:14)
    at Module.Object.<anonymous> (/vitejs-vite-hlfd63/node_modules/jest-preview/dist/styled-components.js:1:203)
    at Runtime._execModule (/vitejs-vite-hlfd63/node_modules/jest-runtime/build/index.js:1646:24)
    at Runtime._loadModule (/vitejs-vite-hlfd63/node_modules/jest-runtime/build/index.js:1185:12)
    at Runtime.requireModule (/vitejs-vite-hlfd63/node_modules/jest-runtime/build/index.js:1009:12)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:2000) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:2000) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Reason is maybe jest-preview try-catch the require('styled-components') wrong way.

try {
import('./styled-components').then(({ getStyle }) => {
fs.writeFileSync(
'./node_modules/.cache/jest-preview-dom/jp-styled-components.css',
getStyle(),
{
encoding: 'utf-8',
flag: 'w',
},
);
});
} catch (error) {
// `styled-components` is not in used
}

@nvh95 nvh95 added the bug Something isn't working label Apr 4, 2022
@nvh95 nvh95 closed this as completed in #17 Apr 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant