sveltejs / vite-plugin-svelte

Svelte plugin for http://vitejs.dev/
MIT License
864 stars 105 forks source link

"Failed to resolve entry" Error attempting to run npm run dev #556

Closed fpolli closed 1 year ago

fpolli commented 1 year ago

Describe the bug

failed to load config from /Users/username/Sites/sitename/vite.config.js error when starting dev server: Error: Build failed with 1 error: node_modules/esbuild/lib/main.js:1355:27: ERROR: [plugin: externalize-deps] Failed to resolve entry for package "@sveltejs/vite-plugin-svelte". The package may have incorrect main/module/exports specified in its package.json: No known conditions for "." entry in "@sveltejs/vite-plugin-svelte" package

Reproduction URL

https://stackblitz.com/edit/vitejs-vite-aupufu?file=index.html&terminal=dev

Reproduction

The Reproduction URL is a dummy. That assumes you are in svelte. My issue is the dev server won't start because it cannot resolve Svelte

My vite.config.js:

import { defineConfig } from "vite"; import laravel from "laravel-vite-plugin"; import { svelte } from '@sveltejs/vite-plugin-svelte';

export default defineConfig({ plugins: [ laravel({ input: ["resources/js/app.js"], refresh: true, valetTls: 'seeds.test' }), svelte({ / plugin options / }) ],

resolve: { alias: { 'ziggy': '/vendor/tightenco/ziggy/src/js' }, },

css: { preprocessorOptions: { scss: { additionalData: '@use "src/variables.scss" as *;', }, }, }, });

Logs

No response

System Info

System:
    OS: macOS 12.6.1
    CPU: (4) x64 Intel(R) Core(TM) i5-7600K CPU @ 3.80GHz
    Memory: 1.70 GB / 32.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 18.12.1 - /usr/local/bin/node
    npm: 8.19.2 - /usr/local/bin/npm
  Browsers:
    Chrome: 108.0.5359.124
    Firefox: 98.0.1
    Safari: 16.1
  npmPackages:
    @sveltejs/vite-plugin-svelte: ^2.0.2 => 2.0.2 
    vite: ^4.0.0 => 4.0.1
beonami commented 1 year ago

I got the same issue. Following the configuration in the release notes, I get the error: laravel is not function. I don't know, is this error coming from laravel-vite-plugin or from @sveltejs/vite-plugin-svelte.

I added "type": "module" to package.json:

package.json
...
  "private": true,
  "type": "module",
  "scripts": {
    "dev": "vite",
...

Error message changed to: laravel is not function and run npm run dev. I hope there is a solution to this problem.

dominikg commented 1 year ago

vite-plugin-svelte is no longer available as commonjs.

This has been documented in the changelog and the FAQ contains an entry about how you can keep using it in commonjs land via dynamic imports.

https://github.com/sveltejs/vite-plugin-svelte/blob/main/docs/faq.md#how-can-i-use-vite-plugin-svelte-from-commonjs

There have also been previous issue reports about this which are easily discovered by searching in this repo https://github.com/sveltejs/vite-plugin-svelte/issues?q=is%3Aissue+%22Failed+to+resolve+entry+for+package%22+

You also did not provide a reproduction and chose to put a useless dummy there instead.

Please try to be better at helping yourself. We are providing a lot of information and it makes me sad if people just ignore that and make me waste time writing things like this up again, which could have been spent making vite-plugin-svelte better for everyone. So please be considerate when filing bugs

fpolli commented 1 year ago

Thank you for the information, which could have been provided without being a dick.

Azmisov commented 1 year ago

For those searching this error, it also gets triggered if you don't put type: module in your package.json.

meduzen commented 1 year ago

For those who come here using the laravel-vite-plugin, this is what helps, awaiting for the Laravel team to come up with ES module instead of CommonJS.