You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When including this library in a React component using Next.js, this error appears:
/home/my_app/node_modules/react-movable/lib/index.js:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,jest){import List from './List.js';
SyntaxError: Cannot use import statement outside a module
This hadn't happened to me with any of the many other libraries I had imported in the frontend of my project.
To be honest I'm not sure what would be the solution here. Maybe re-arrange the way files are exported/imported inside the library.
Current Workaround
In my jest.config.mjs file, I changed the way the config is exported. Note that in Next.js the convention is to use nextJest to generate the configuration object, and to export an async function.
importnextJestfrom'next/jest.js';constcreateJestConfig=nextJest({// Provide the path to your Next.js app to load next.config.js and .env files in your test environmentdir: './',});// Add any custom config to be passed to Jest/** @type {import('jest').Config} */constconfig={setupFilesAfterEnv: ['<rootDir>/jest.setup.ts'],testEnvironment: "jest-environment-jsdom"};asyncfunctionjestConfig(...args){constnextJestConfig=awaitcreateJestConfig(config)(...args)// HERE, don't ignore react-movable when transforming files.nextJestConfig.transformIgnorePatterns=nextJestConfig.transformIgnorePatterns.map(pattern=>{if(pattern==='/node_modules/'){return'/node_modules(?!/react-movable)/'}returnpattern})returnnextJestConfig}exportdefaultjestConfig
Then run Jest and it works.
The text was updated successfully, but these errors were encountered:
ChrisVilches
changed the title
React Movable makes it hard to write tests in Next.js
React Movable makes it hard to write tests in Next.js (with Jest)
Jun 9, 2023
When including this library in a React component using Next.js, this error appears:
This hadn't happened to me with any of the many other libraries I had imported in the frontend of my project.
To be honest I'm not sure what would be the solution here. Maybe re-arrange the way files are exported/imported inside the library.
Current Workaround
In my
jest.config.mjs
file, I changed the way the config is exported. Note that in Next.js the convention is to usenextJest
to generate the configuration object, and to export an async function.Then run Jest and it works.
The text was updated successfully, but these errors were encountered: