imagetools: Failed to resolve entry for package "vite-imagetools"

Hi, after upgrading to v5.0.3 I get in a Laravel project the following error:

✘ [ERROR] Failed to resolve entry for package "vite-imagetools". 
The package may have incorrect main/module/exports specified in its package.json: No known conditions for "." specifier in "vite-imagetools" package [plugin externalize-deps]

    node_modules/esbuild/lib/main.js:1360:27:
      1360 │         let result = await callback({
  This error came from the "onResolve" callback registered here:

    node_modules/esbuild/lib/main.js:1279:20:
      1279 │       let promise = setup({
  The plugin "externalize-deps" was triggered by this import

    vite.config.js:8:27:
      8 │ import { imagetools } from 'vite-imagetools';

Node: v19.9.0 OS: Mac M1, Ventura 13.3.1 (a)

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 2
  • Comments: 15

Most upvoted comments

Edit: Build is successful after changing vite.config.ts to vite.config.mts as suggested earlier here.

Glad you got it working. I should clarify that approach is really just a temporary hack. You’d be much better off adding "type": "module" to your package.json and then converting your postcss and tailwind configs to use modern ESM syntax instead of module.exports

But I still wonder why this fix is required

It’s because your project is building into the legacy CJS format and vite-imagetools 5.x is only available as an ESM module. You should migrate away from the legacy format by adding "type": "module" to your package.json

Can you help me to understand why we should change the file-extension to .mts for just one package while all other packages are running fine without this modification?

import is the JS standard way of doing package imports. require is something the Node team made up themselves before import was available. It’s a terrible mess that the ecosystem is in by having to support both. The sooner everyone is using import and require is completely dead, the better off we’ll all be. Projects need to start migrating by adding "type": "module" to their package.json. There are tons of other libraries that will require the same from you (e.g. basically the entire Svelte ecosystem only supports ESM). This is just the first library you happened to encounter requiring it in your particular project, but it’s the way everything is going and you’ll be forced to migrate sooner or later.

changing vite.config.ts to vite.config.mts works for qwik 😄