Describe the bug
I have a custom plugin in my Vendure project, which reads some configuration data from a local JSON file.
Whenever I import this plugin in vendure-config.ts and try to run the dashboard in dev mode, I get a "module not found" error related to my JSON file.
After some digging, I found out that vendureDashboardPlugin reads vendure-config.ts , does a manual lookup of all relative imports (including transitive), transpiles them and then copies them to /node_modules/@vendure/dashboard/dist/vite/.vendure-dashboard-temp. At runtime, the transpiled vendure-config.js will be evaluated, but in my case it will throw an error, since the transitive import to ./google-sheet-config.json is not found.
This is due to the compileTypeScript and collectLocalSourceFiles functions only accounting for ts, tsx, js and jsx files, but not json. Having set "resolveJsonModule": true in my tsconfig.json, I'd expect this setting to be honoured by the dashboard compilation as well.
To Reproduce
Steps to reproduce the behavior:
- Create a test-data.json file with any content, e.g.
{"foo":"bar"}, next to vendure-config.ts.
- Add
"resolveJsonModule": true to tsconfig.json compilerOptions.
- Add the following lines to
vendure-config.ts:
import testData from './test-data.json';
console.log('TEST DATA', testData);
- Start the Vendure server. You should see the test data logged to stdout.
- Start the dashboard app in dev mode (
vite --clearScreen false).
Expected behavior
Dashboard server starts in dev mode without errors.
Actual behavior
Dashboard server crashes with Error: Error loading Vendure config: Error loading config: Cannot find module './test-data.json'
Screenshots/Videos
If applicable, add screenshots or videos to help explain your problem.
Error logs
My original stacktrace:
Require stack:
- /path_to_project/vendure/node_modules/@vendure/dashboard/dist/vite/.vendure-dashboard-temp/plugins/google-sheets-integration/google-sheets-integration.plugin.js
- /path_to_project/vendure/node_modules/@vendure/dashboard/dist/vite/.vendure-dashboard-temp/vendure-config.js
Error: Cannot find module './google-sheet-config.json'
Require stack:
- /path_to_project/vendure/node_modules/@vendure/dashboard/dist/vite/.vendure-dashboard-temp/plugins/google-sheets-integration/google-sheets-integration.plugin.js
- /path_to_project/vendure/node_modules/@vendure/dashboard/dist/vite/.vendure-dashboard-temp/vendure-config.js
at Module.<anonymous> (node:internal/modules/cjs/loader:1456:15)
at Module._resolveFilename (/path_to_project/vendure/node_modules/tsconfig-paths/lib/register.js:103:40)
at defaultResolveImpl (node:internal/modules/cjs/loader:1066:19)
at resolveForCJSWithHooks (node:internal/modules/cjs/loader:1071:22)
at Module._load (node:internal/modules/cjs/loader:1242:25)
at wrapModuleLoad (node:internal/modules/cjs/loader:255:19)
at Module.require (node:internal/modules/cjs/loader:1556:12)
at require (node:internal/modules/helpers:152:16)
at Object.<anonymous> (/path_to_project/vendure/node_modules/@vendure/dashboard/dist/vite/.vendure-dashboard-temp/plugins/google-sheets-integration/google-sheets-integration.plugin.js:21:52)
at Module._compile (node:internal/modules/cjs/loader:1812:14)
If you are using a monorepo, you may need to provide a custom pathAdapter to resolve the paths correctly.
at PluginContext._formatLog (file:///path_to_project/vendure/node_modules/vite/dist/node/chunks/config.js:29079:43)
at PluginContext.error (file:///path_to_project/vendure/node_modules/vite/dist/node/chunks/config.js:29076:14)
at PluginContext.buildStart (file:///path_to_project/vendure/node_modules/@vendure/dashboard/dist/vite/vite-plugin-config-loader.js:39:26)
at async Promise.all (index 5)
at async EnvironmentPluginContainer.hookParallel (file:///path_to_project/vendure/node_modules/vite/dist/node/chunks/config.js:28741:3)
at async EnvironmentPluginContainer.buildStart (file:///path_to_project/vendure/node_modules/vite/dist/node/chunks/config.js:28751:3)
at async file:///path_to_project/vendure/node_modules/vite/dist/node/chunks/config.js:25712:4
at async httpServer.listen (file:///path_to_project/vendure/node_modules/vite/dist/node/chunks/config.js:25723:5)
Environment (please complete the following information):
- @vendure/core version: 3.6.4
- Nodejs version: v22.14.0
- Database (mysql/postgres etc): postgres
- Operating System (Windows/macOS/Linux): Fedora Linux
- Browser (if applicable): N/A
- Package manager (npm/yarn/pnpm): npm
Workaround
Extra logic in vendure-config.ts to not include my plugin if the process command string starts with "vite".
Additional context
My plugin is strictly related to the Vendure server functionality - it has nothing to do with the dashboard app. As you can see in the steps to reproduce, this error occurs also when a JSON file is imported directly in the config file, without any plugins involved.
The same error occurs when building the dashboard in production mode as well.
It's worth noting that everything was working well on version 3.5.5, but once I upgraded to 3.6.4, I started getting this error.
Describe the bug
I have a custom plugin in my Vendure project, which reads some configuration data from a local JSON file.
Whenever I import this plugin in vendure-config.ts and try to run the dashboard in dev mode, I get a "module not found" error related to my JSON file.
After some digging, I found out that
vendureDashboardPluginreadsvendure-config.ts, does a manual lookup of all relative imports (including transitive), transpiles them and then copies them to/node_modules/@vendure/dashboard/dist/vite/.vendure-dashboard-temp. At runtime, the transpiledvendure-config.jswill be evaluated, but in my case it will throw an error, since the transitive import to./google-sheet-config.jsonis not found.This is due to the
compileTypeScriptandcollectLocalSourceFilesfunctions only accounting for ts, tsx, js and jsx files, but not json. Having set"resolveJsonModule": truein mytsconfig.json, I'd expect this setting to be honoured by the dashboard compilation as well.To Reproduce
Steps to reproduce the behavior:
{"foo":"bar"}, next tovendure-config.ts."resolveJsonModule": trueto tsconfig.jsoncompilerOptions.vendure-config.ts:vite --clearScreen false).Expected behavior
Dashboard server starts in dev mode without errors.
Actual behavior
Dashboard server crashes with
Error: Error loading Vendure config: Error loading config: Cannot find module './test-data.json'Screenshots/Videos
If applicable, add screenshots or videos to help explain your problem.
Error logs
My original stacktrace:
Environment (please complete the following information):
Workaround
Extra logic in
vendure-config.tsto not include my plugin if the process command string starts with "vite".Additional context
My plugin is strictly related to the Vendure server functionality - it has nothing to do with the dashboard app. As you can see in the steps to reproduce, this error occurs also when a JSON file is imported directly in the config file, without any plugins involved.
The same error occurs when building the dashboard in production mode as well.
It's worth noting that everything was working well on version 3.5.5, but once I upgraded to 3.6.4, I started getting this error.