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
[INFO] --- frontend-maven-plugin:1.15.1:npx (lint:eslint) @ handlereg.web.frontend ---
[INFO] Running 'npx eslint . --ext js --report-unused-disable-directives --max-warnings 0' in /home/sb/workspaces/handlereg/handlereg.web.frontend/src/main/frontend
[INFO] (node:779317) [MODULE_TYPELESS_PACKAGE_JSON] Warning: Module type of file:///home/sb/workspaces/handlereg/handlereg.web.frontend/src/main/frontend/eslint.config.js?mtime=1751812432629 is not specified and it doesn't parse as CommonJS.
[INFO] Reparsing as ES module because module syntax was detected. This incurs a performance overhead.
[INFO] To eliminate this warning, add "type": "module" to /home/sb/workspaces/handlereg/handlereg.web.frontend/src/main/frontend/package.json.
So I put
"type": "module",
into package.json which made npx eslint run without warning.
However the change that made the eslint warning go away broke npx vite build further down:
[INFO] --- frontend-maven-plugin:1.15.1:npx (vite-build) @ handlereg.web.frontend ---
[INFO] Running 'npx vite build' in /home/sb/workspaces/handlereg/handlereg.web.frontend/src/main/frontend
[INFO] vite v7.0.5 building for production...
[INFO]
[INFO] (!) outDir /home/sb/workspaces/handlereg/handlereg.web.frontend/target/classes is not inside project root and will not be emptied.
[INFO] Use --emptyOutDir to override.
[INFO]
[INFO] transforming...
[INFO] file:///home/sb/workspaces/handlereg/handlereg.web.frontend/src/main/frontend/node_modules/.vite-temp/vite.config.js.timestamp-1753347247751-f7f4ddc73fff9.mjs:44
[INFO] traverse(ast, {
[INFO] ^
[INFO]
[INFO] TypeError: traverse is not a function
[INFO] at file:///home/sb/workspaces/handlereg/handlereg.web.frontend/src/main/frontend/node_modules/.vite-temp/vite.config.js.timestamp-1753347247751-f7f4ddc73fff9.mjs:44:11
[INFO] at FSReqCallback.readFileAfterClose [as oncomplete] (node:internal/fs/read/context:68:3)
[INFO]
[INFO] Node.js v22.17.0
The error occurs in my own vite plugin that scans for react-router routes and puts the routes in a flat text file that can be read by the Java servlet servlng the react frontend so that it can return index.html on all navigable routes and 404 on the rest.
Ideas, workarounds and tips on what's going on are all welcome!
Thanks in advance!
(I have been down this rabbit hole earlier, and then tried to run babel on vite.config.js but that failed... I suspect a hen-and-egg-problem since vite is what is running babel to transform the ES into javascript...?)
Here is the vite.config.js file containing the exportRoutesPlugin:
import{defineConfig}from'vite';importpathfrom'path';importfsfrom'fs';import{parse}from'@babel/parser';importtraversefrom'@babel/traverse';import*astfrom"@babel/types";exportdefaultdefineConfig({plugins: [exportRoutesPlugin()],build: {minify: false,sourcemap: true,manifest: true,rollupOptions: {// overwrite default .html entryinput: 'src/index.js',output: {entryFileNames: `assets/[name].js`,chunkFileNames: `assets/[name].js`,assetFileNames: `assets/[name].[ext]`}},// Relative to the rootoutDir: '../../../target/classes',},// Treat .js files as jsxesbuild: {include: /\.js$/,exclude: [],loader: 'jsx',},});functionexportRoutesPlugin(){constroutePaths=newSet();return{name: 'export-routes',asynctransform(src,id){if(!id.includes('node_modules')&&!id.includes('commonjsHelpers')&&id.includes('.js')){// This is a rollup plugin that runs after esbuild, so code in src has already been processed// from JSX to plain JS (i.e. the JSX stuff is gone...).// Have to read the raw file from disk to find the JSX tags.fs.readFile(id,'utf-8',(err,data)=>{constast=parse(data,{sourceType: 'module',plugins: ['jsx'],});traverse(ast,{enter(path){if(t.isJSXElement(path.node)){constelementName=path.node.openingElement.name.name;if(elementName==='Route'){path.node.openingElement.attributes.forEach((attribute)=>{if(attribute.name.name==='path'){routePaths.add(attribute.value.value);}});}}}});});}},generateBundle(options,bundle){constoutputDirectory=options.dir||'dist';constassetsDirectory=path.join(outputDirectory,'assets');fs.mkdirSync(assetsDirectory,{recursive: true});constfilePath=path.join(assetsDirectory,'routes.txt');constfileContent=Array.from(routePaths).join('\n');fs.writeFileSync(filePath,fileContent);},};};
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Today I decided to look into this warning
So I put
into
package.json
which madenpx eslint
run without warning.However the change that made the eslint warning go away broke
npx vite build
further down:The error occurs in my own vite plugin that scans for react-router routes and puts the routes in a flat text file that can be read by the Java servlet servlng the react frontend so that it can return
index.html
on all navigable routes and 404 on the rest.Ideas, workarounds and tips on what's going on are all welcome!
Thanks in advance!
(I have been down this rabbit hole earlier, and then tried to run babel on vite.config.js but that failed... I suspect a hen-and-egg-problem since vite is what is running babel to transform the ES into javascript...?)
Here is the
vite.config.js
file containing theexportRoutesPlugin
:Beta Was this translation helpful? Give feedback.
All reactions