Skip to content
This repository has been archived by the owner on Jun 13, 2024. It is now read-only.

Fails with commonjs file (vite.config.ts) #7

Open
reinerBa opened this issue Feb 26, 2022 · 5 comments
Open

Fails with commonjs file (vite.config.ts) #7

reinerBa opened this issue Feb 26, 2022 · 5 comments

Comments

@reinerBa
Copy link

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
Copy link
Author

reinerBa commented Feb 26, 2022

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 reinerBa changed the title Fails with ts Fails with commonjs file (vite.config.ts) Feb 26, 2022
@reinerBa
Copy link
Author

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
Copy link
Author

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

@sean-hill
Copy link

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.

@AdminHcat
Copy link

need to add support for typescript

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants