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
I'm trying to migrate a project from CRA+Jest to Vite+Vitest, so far everything went well but now i'm stuck at a point where vitest is failing the majority of the tests with the same error:
SyntaxError: Invalid or unexpected token
- /node_modules/antd/lib/date-picker/style/index.js:3:1
Digging into this file reveals that this file is doing require to other file who contains a LESS variable
Invalid or unexpected token
/Users/oferitz/Projects/my-project/node_modules/antd/lib/date-picker/style/index.less:1
@root-entry-name: default;
^
Now in the app itself everything is working fine, the app transpiles, all less files and variables resolved correctly with this vite.config.ts
/// <reference types="vitest" />import{defineConfig}from'vite'importreactfrom'@vitejs/plugin-react'importcheckerfrom'vite-plugin-checker'importtsconfigPathsfrom'vite-tsconfig-paths'importeslintPluginfrom'vite-plugin-eslint'importsvgrfrom'vite-plugin-svgr'importvitePluginImpfrom'vite-plugin-imp'import{configDefaults}from'vitest/config'exportdefaultdefineConfig(({ mode })=>{return{build: {sourcemap: true},css: {preprocessorOptions: {less: {javascriptEnabled: true,modifyVars: {// LESS variables}}}},resolve: {alias: [// Alias for Ant Design less files{find: /^~/,replacement: ''}]},plugins: [react(),vitePluginImp({libList: [{libName: 'antd',libDirectory: 'es',style: name=>`antd/es/${name}/style`}]}),svgr(),checker({typescript: true}),tsconfigPaths(),eslintPlugin()],define: {
...(mode==='development'&&{global: 'window','process.env': {}})},test: {globals: true,environment: 'jsdom',setupFiles: './src/setupTests.ts'}}})
To my understanding Vitest is using the above config so what am i missing here?
I tried to set some configuration options like deps : {fallbackCJS : true} but it didn't help...
Any help will be appreciated.
I had a problem with antd styles as well but the solution above me did not work maybe because antd was used by a dependency, so I created a PR to fix it in: #3465 and it's fixed in v0.31.2
Describe the bug
I'm trying to migrate a project from CRA+Jest to Vite+Vitest, so far everything went well but now i'm stuck at a point where vitest is failing the majority of the tests with the same error:
Digging into this file reveals that this file is doing require to other file who contains a LESS variable
index.less
So the underlying error is actually:
Now in the app itself everything is working fine, the app transpiles, all less files and variables resolved correctly with this
vite.config.ts
To my understanding Vitest is using the above config so what am i missing here?
I tried to set some configuration options like
deps : {fallbackCJS : true}
but it didn't help...Any help will be appreciated.
Reproduction
System Info
Used Package Manager
npm
Validations
The text was updated successfully, but these errors were encountered: