vite Uncaught ReferenceError: require is not defined

  1. Prefer to resolve by modifying the source code; remember to restart after modification, some dependencies may need reprocessing.


  1. Alternatively, use pre-bundling or CommonJS plugins to handle it.

To solve this problem, I briefly tried several CommonJS plugins found through search, and finally chose @rollup/plugin-commonjs based on considerations of maturity, reliability, and comprehensiveness.

import commonjs from '@rollup/plugin-commonjs';

export default defineConfig({ plugins: [ commonjs({ transformMixedEsModules: true, include: ['path/to/xxx.js'], }), ], });

https://juejin.cn/post/7017446703296937998



评论

暂无评论。

登录后可发表评论。