vite-plugin-sri icon indicating copy to clipboard operation
vite-plugin-sri copied to clipboard

Fails with commonjs file (vite.config.ts)

Open reinerBa opened this issue 3 years ago • 5 comments

Hi, i used the codelines from your readme.md in my vite.config.ts file. This happens when i triy to build: failed to load config from ...\vite.config.ts error during build: Error [ERR_REQUIRE_ESM]: require() of ES Module ...\node_modules\@small-tech\vite-plugin-sri\index.js from ...\vite.config.ts not supported. Instead change the require of index.js in c:\Dev\Try\my-vue-appts\vite.config.ts to a dynamic import() which is available in all CommonJS modules.

When i try to use require instead of import: failed to load config from ...\vite.config.ts error during build: Error [ERR_REQUIRE_ESM]: require() of ES Module ...\node_modules\@small-tech\vite-plugin-sri\index.js from ...\vite.config.ts not supported. Instead change the require of index.js in c:\Dev\Try\my-vue-appts\vite.config.ts to a dynamic import() which is available in all CommonJS modules.

Can you please build the library in a way i can be imported?

reinerBa avatar Feb 26 '22 19:02 reinerBa

It works with async define config in vite and async import. Not a nice solution but it seems to work

import { defineConfig } from 'vite'

export default defineConfig(async ({ command, mode }) => {
  const sri = await import('@small-tech/vite-plugin-sri')
  return {
	plugins: [sri.default()]
  }
})

reinerBa avatar Feb 26 '22 19:02 reinerBa

Ok so would need that module filed in the package.json, which is not included in the vite-> vue template

https://bobbyhadz.com/blog/javascript-error-err-require-esm-require-of-es-module-not-supported

reinerBa avatar Feb 26 '22 20:02 reinerBa

Please publish the current codebase on npm. In the npm version is no cjs file and no exports property in the package.json

reinerBa avatar Feb 26 '22 22:02 reinerBa

I'm getting this same error as well 😭

failed to load config from /Users/seanhill/dev/atomic/transact/vite.config.js
error when starting dev server:
Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/seanhill/dev/atomic/transact/node_modules/@small-tech/vite-plugin-sri/index.js from /Users/seanhill/dev/atomic/transact/vite.config.js not supported.
Instead change the require of index.js in /Users/seanhill/dev/atomic/transact/vite.config.js to a dynamic import() which is available in all CommonJS modules.

sean-hill avatar Jul 14 '22 19:07 sean-hill

need to add support for typescript

AdminHcat avatar Sep 23 '22 23:09 AdminHcat