rollup – How to config vite to transpile both commonjs and module for packages in node_modules

I have imported a packages that are commonjs and module type.
While building, it will throw these type of errors.

SyntaxError: Named export 'getEnv' not found. The requested module 'IMPORTED_PACKAGE' is a CommonJS module, which may not support all module.exports as named exports.
SyntaxError: Cannot use import statement outside a module

I also have to manually go into the package folder in node_modules to fix file extension like this

BEFORE: import _has from ‘lodash/has’;

AFTER: import _has from ‘lodash/has.js’;

I have tried finding a vite config that will resolve this but no luck.

Read more here: Source link