sveltejs / kit

web development, streamlined
https://kit.svelte.dev
MIT License
18.43k stars 1.88k forks source link

Missing "." export in "@sveltejs/kit" package #2384

Closed jacobbogers closed 3 years ago

jacobbogers commented 3 years ago

Describe the bug

When issue npm run build get this error

Reproduction

npm run build

My svelte.config.js

import preprocess from 'svelte-preprocess';
const config = {

    kit: {
        amp: false,
        appDir: '_app',
        files: {
            assets: 'static',
            //hooks: 'src/hooks',
            lib: 'src/lib',
            routes: 'src/routes',
            serviceWorker: 'src/service-worker.ts',
            template: 'src/app.html'
        },
        floc: false,
        hydrate: true,
        package: {
            files: {
                exclude: ['**/*.test.ts']
            }
        },
        prerender: {
            crawl: true,
            enabled: true,
            onError: 'continue',
            pages: ['*']
        },
        router: true,
        ssr: true,
        target: '#svelte',
        trailingSlash: 'never'
    },
    preprocess: preprocess({
        replace: [['process.env.NODE_ENV', JSON.stringify(process.env.NODE_ENV)]],
    }),
};

export default config;

My package.json

{
  "name": "~TODO~",
  "version": "0.0.1",
  "scripts": {
    "dev": "svelte-kit dev",
    "build": "svelte-kit build",
    "preview": "svelte-kit preview",
    "check": "svelte-check --tsconfig ./tsconfig.json",
    "check:watch": "svelte-check --tsconfig ./tsconfig.json --watch",
    "lint": "prettier --check --plugin-search-dir=. . && eslint --ignore-path .gitignore .",
    "format": "prettier --write --plugin-search-dir=. .",
    "test": "jest"
  },
  "//": "force install svelte-jester on version 1.8.2, 2.1.1 is broken and being fixed",
  "devDependencies": {
    "@sveltejs/kit": "next",
    "@testing-library/jest-dom": "^5.14.1",
    "@testing-library/svelte": "^3.0.3",
    "@types/jest": "^27.0.1",
    "@typescript-eslint/eslint-plugin": "^4.19.0",
    "@typescript-eslint/parser": "^4.19.0",
    "eslint": "^7.22.0",
    "eslint-config-prettier": "^8.1.0",
    "eslint-plugin-svelte3": "^3.2.0",
    "jest": "^27.1.0",
    "jest-localstorage-mock": "^2.4.17",
    "prettier": "~2.2.1",
    "prettier-plugin-svelte": "^2.2.0",
    "svelte": "^3.34.0",
    "svelte-check": "^2.0.0",
    "svelte-jester": "1.8.2",
    "svelte-preprocess": "^4.0.0",
    "ts-jest": "^27.0.5",
    "tslib": "^2.0.0",
    "typescript": "^4.0.0"
  },
  "type": "module"
}

Logs

npm run build

> ~TODO~@0.0.1 build
> svelte-kit build

vite v2.5.4 building for production...
✓ 30 modules transformed.
.svelte-kit/output/client/_app/manifest.json                               1.30 KiB
.svelte-kit/output/client/_app/error.svelte-89ee8862.js                    1.55 KiB / brotli: 0.64 KiB
.svelte-kit/output/client/_app/pages/__layout.svelte-a8251f0c.js           0.72 KiB / brotli: 0.41 KiB
.svelte-kit/output/client/_app/assets/start-61d1577b.css                   0.16 KiB / brotli: 0.11 KiB
.svelte-kit/output/client/_app/assets/pages/__layout.svelte-3c7a1a64.css   0.72 KiB / brotli: 0.37 KiB
.svelte-kit/output/client/_app/assets/pages/index.svelte-7545cfa0.css      2.71 KiB / brotli: 0.65 KiB
.svelte-kit/output/client/_app/chunks/vendor-401acf23.js                   7.57 KiB / brotli: 2.79 KiB
.svelte-kit/output/client/_app/pages/index.svelte-0ea4a5cb.js              10.38 KiB / brotli: 3.38 KiB
.svelte-kit/output/client/_app/start-2fb977ed.js                           17.60 KiB / brotli: 5.62 KiB
vite v2.5.4 building SSR bundle for production...
Bundling package for SSR due to resolve failure. Failed to resolve entry for package "@sveltejs/kit". The package may have incorrect main/module/exports specified in its package.json: Missing "." export in "@sveltejs/kit" package     
Bundling package for SSR due to resolve failure. Failed to resolve entry for package "@types/jest". The package may have incorrect main/module/exports specified in its package.json: Failed to resolve entry for package "@types/jest". The package may have incorrect main/module/exports specified in its package.json.
✓ 29 modules transformed.
.svelte-kit/output/server/app.js   83.31 KiB
vite v2.5.4 building for production...
✓ 2 modules transformed.
.svelte-kit/output/client/service-worker.js   0.41 KiB / brotli: 0.20 KiB

Run npm run preview to preview your production build locally.

System Info

node version: v16.3.0
svelte-kit, 1.0.0-next.164

Severity

serious, but I can work around it

Additional Information

No response

HeritagePalms commented 3 years ago

I get the same thing once I upgraded to sveltekit 1.0.0-next.164. The two packages for me though are: sveltejs/adapter-vercel sveltejs/kit

GageBachik commented 3 years ago

Bump. Same error upon even making a brand new repo.

Simply running:

npm init svelte@next test cd test npm run dev

produces:

Bundling package for SSR due to resolve failure. Failed to resolve entry for package "@sveltejs/kit". The package may have incorrect main/module/exports specified in its package.json: Missing "." export in "@sveltejs/kit" package

yogenpoonudurai commented 3 years ago

Bump. Same here.

SvelteKit v1.0.0-next.164

Bundling package for SSR due to resolve failure. Failed to resolve entry for package "@sveltejs/kit". The package may have incorrect main/module/exports specified in its package.json: Missing "." export in "@sveltejs/kit" package

benmccann commented 3 years ago

This message will be silenced in the next Vite release https://github.com/vitejs/vite/pull/4873

mweissen commented 3 years ago

Same problem. I tried to use swiper. (Yes, it is installed!)

Bundling package for SSR due to resolve failure. Failed to resolve entry for package "@sveltejs/kit". The package may have incorrect main/module/exports specified in its package.json: Missing "." export in "@sveltejs/kit" package

Cannot find module 'swiper' from 'C:/Svelte/tw08swip/src/routes/swip' Cannot find module 'swiper/svelte' from 'C:/Svelte/tw08swip/src/routes/swip'

bluwy commented 3 years ago

Vite had already made another release (2.5.6), what's left is to upgrade Vite

benmccann commented 3 years ago

I cut a release with a new version of Vite

janosh commented 2 years ago

I think I'm still encountering this error:

  "devDependencies": {
    "@sveltejs/adapter-static": "^1.0.0-next.20",
    "@sveltejs/kit": "^1.0.0-next.179",
    "svelte": "^3.43.1",
    "svelte-preprocess": "^4.9.8",
    "typescript": "^4.4.3",
    "vite": "^2.6.2",
    ...
  }
$ svelte-kit dev
 > node_modules/vite/dist/node/chunks/dep-24231913.js:44016:10: error: [plugin: vite:dep-scan] Failed to resolve entry for package "@sveltejs/kit". The package may have incorrect main/module/exports specified in its package.json: Missing "." export in "@sveltejs/kit" package
    44016 │     throw new Error(`Failed to resolve entry for package "${id}". ` +
          ╵           ^
    at packageEntryFailure (/Users/janosh/Repos/tikz/site/node_modules/vite/dist/node/chunks/dep-24231913.js:44016:11)
    at resolvePackageEntry (/Users/janosh/Repos/tikz/site/node_modules/vite/dist/node/chunks/dep-24231913.js:44012:9)
    at tryNodeResolve (/Users/janosh/Repos/tikz/site/node_modules/vite/dist/node/chunks/dep-24231913.js:43787:11)
    at Context.resolveId (/Users/janosh/Repos/tikz/site/node_modules/vite/dist/node/chunks/dep-24231913.js:43647:28)
    at Object.resolveId (/Users/janosh/Repos/tikz/site/node_modules/vite/dist/node/chunks/dep-24231913.js:50533:55)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async resolve (/Users/janosh/Repos/tikz/site/node_modules/vite/dist/node/chunks/dep-24231913.js:50720:26)
    at async /Users/janosh/Repos/tikz/site/node_modules/vite/dist/node/chunks/dep-24231913.js:50838:34
    at async callback (/Users/janosh/Repos/tikz/site/node_modules/esbuild/lib/main.js:832:28)
    at async handleRequest (/Users/janosh/Repos/tikz/site/node_modules/esbuild/lib/main.js:664:30)

   node_modules/vite/dist/node/chunks/dep-24231913.js:50828:18: note: This error came from the "onResolve" callback registered here
    50828 │             build.onResolve({
          ╵                   ~~~~~~~~~
    at setup (/Users/janosh/Repos/tikz/site/node_modules/vite/dist/node/chunks/dep-24231913.js:50828:19)
    at handlePlugins (/Users/janosh/Repos/tikz/site/node_modules/esbuild/lib/main.js:756:23)
    at Object.buildOrServe (/Users/janosh/Repos/tikz/site/node_modules/esbuild/lib/main.js:1044:7)
    at /Users/janosh/Repos/tikz/site/node_modules/esbuild/lib/main.js:1886:17
    at new Promise (<anonymous>)
    at Object.build (/Users/janosh/Repos/tikz/site/node_modules/esbuild/lib/main.js:1885:14)
    at Object.build (/Users/janosh/Repos/tikz/site/node_modules/esbuild/lib/main.js:1740:51)
    at /Users/janosh/Repos/tikz/site/node_modules/vite/dist/node/chunks/dep-24231913.js:50679:54
    at Array.map (<anonymous>)

   html:/Users/janosh/Repos/tikz/site/src/routes/__error.svelte:18:7: note: The plugin "vite:dep-scan" was triggered by this import
       18 │ import '@sveltejs/kit'
          ╵        ~~~~~~~~~~~~~~~

 > node_modules/vite/dist/node/chunks/dep-24231913.js:44016:10: error: [plugin: vite:dep-scan] Failed to resolve entry for package "@sveltejs/kit". The package may have incorrect main/module/exports specified in its package.json: Missing "." export in "@sveltejs/kit" package
    44016 │     throw new Error(`Failed to resolve entry for package "${id}". ` +
          ╵           ^
    at packageEntryFailure (/Users/janosh/Repos/tikz/site/node_modules/vite/dist/node/chunks/dep-24231913.js:44016:11)
    at resolvePackageEntry (/Users/janosh/Repos/tikz/site/node_modules/vite/dist/node/chunks/dep-24231913.js:44012:9)
    at tryNodeResolve (/Users/janosh/Repos/tikz/site/node_modules/vite/dist/node/chunks/dep-24231913.js:43787:11)
    at Context.resolveId (/Users/janosh/Repos/tikz/site/node_modules/vite/dist/node/chunks/dep-24231913.js:43647:28)
    at Object.resolveId (/Users/janosh/Repos/tikz/site/node_modules/vite/dist/node/chunks/dep-24231913.js:50533:55)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async resolve (/Users/janosh/Repos/tikz/site/node_modules/vite/dist/node/chunks/dep-24231913.js:50720:26)
    at async /Users/janosh/Repos/tikz/site/node_modules/vite/dist/node/chunks/dep-24231913.js:50838:34
    at async callback (/Users/janosh/Repos/tikz/site/node_modules/esbuild/lib/main.js:832:28)
    at async handleRequest (/Users/janosh/Repos/tikz/site/node_modules/esbuild/lib/main.js:664:30)

   node_modules/vite/dist/node/chunks/dep-24231913.js:50828:18: note: This error came from the "onResolve" callback registered here
    50828 │             build.onResolve({
          ╵                   ~~~~~~~~~
    at setup (/Users/janosh/Repos/tikz/site/node_modules/vite/dist/node/chunks/dep-24231913.js:50828:19)
    at handlePlugins (/Users/janosh/Repos/tikz/site/node_modules/esbuild/lib/main.js:756:23)
    at Object.buildOrServe (/Users/janosh/Repos/tikz/site/node_modules/esbuild/lib/main.js:1044:7)
    at /Users/janosh/Repos/tikz/site/node_modules/esbuild/lib/main.js:1886:17
    at new Promise (<anonymous>)
    at Object.build (/Users/janosh/Repos/tikz/site/node_modules/esbuild/lib/main.js:1885:14)
    at Object.build (/Users/janosh/Repos/tikz/site/node_modules/esbuild/lib/main.js:1740:51)
    at /Users/janosh/Repos/tikz/site/node_modules/vite/dist/node/chunks/dep-24231913.js:50679:54
    at Array.map (<anonymous>)

   html:/Users/janosh/Repos/tikz/site/src/routes/[slug].svelte:40:7: note: The plugin "vite:dep-scan" was triggered by this import
       40 │ import '@sveltejs/kit'
          ╵        ~~~~~~~~~~~~~~~

> Build failed with 2 errors:
node_modules/vite/dist/node/chunks/dep-24231913.js:44016:10: error: [plugin: vite:dep-scan] Failed to resolve entry for package "@sveltejs/kit". The package may have incorrect main/module/exports specified in its package.json: Missing "." export in "@sveltejs/kit" package
node_modules/vite/dist/node/chunks/dep-24231913.js:44016:10: error: [plugin: vite:dep-scan] Failed to resolve entry for package "@sveltejs/kit". The package may have incorrect main/module/exports specified in its package.json: Missing "." export in "@sveltejs/kit" package
Error: Build failed with 2 errors:
node_modules/vite/dist/node/chunks/dep-24231913.js:44016:10: error: [plugin: vite:dep-scan] Failed to resolve entry for package "@sveltejs/kit". The package may have incorrect main/module/exports specified in its package.json: Missing "." export in "@sveltejs/kit" package
node_modules/vite/dist/node/chunks/dep-24231913.js:44016:10: error: [plugin: vite:dep-scan] Failed to resolve entry for package "@sveltejs/kit". The package may have incorrect main/module/exports specified in its package.json: Missing "." export in "@sveltejs/kit" package
    at failureErrorWithLog (/Users/janosh/Repos/tikz/site/node_modules/esbuild/lib/main.js:1493:15)
    at /Users/janosh/Repos/tikz/site/node_modules/esbuild/lib/main.js:1151:28
    at runOnEndCallbacks (/Users/janosh/Repos/tikz/site/node_modules/esbuild/lib/main.js:941:63)
    at buildResponseToResult (/Users/janosh/Repos/tikz/site/node_modules/esbuild/lib/main.js:1149:7)
    at /Users/janosh/Repos/tikz/site/node_modules/esbuild/lib/main.js:1258:14
    at /Users/janosh/Repos/tikz/site/node_modules/esbuild/lib/main.js:629:9
    at handleIncomingPacket (/Users/janosh/Repos/tikz/site/node_modules/esbuild/lib/main.js:726:9)
    at Socket.readFromStdout (/Users/janosh/Repos/tikz/site/node_modules/esbuild/lib/main.js:596:7)
    at Socket.emit (node:events:390:28)
    at Socket.emit (node:domain:475:12)
error Command failed with exit code 1.
MarcusCemes commented 2 years ago

In case this helps anyone, I ran into the same problem after replacing all occurrences of import type { ... } with import { ... }.

TypeScript users no longer have to strictly separate type imports and value imports (...) - Svelte October blog post

It seems that some imports, such as those importing from @svelte/kit or those in <script context="module"> still need explicit type imports (I'm not sure which is the cause). Another solution is to use JS and a @type hint such as in the Svelte docs.

<script context="module" lang="ts">
  import type { Load } from "@sveltejs/kit";
  export const load: Load = async ({ page, fetch }) => {
<script context="module">
  /**
   * @type {import("@svelte/kit").Load}
   */
  export async function load({ page, fetch }) {
dummdidumm commented 2 years ago

If the import consists of type imports only, you need to use import type

rburgst commented 2 years ago

If the import consists of type imports only, you need to use import type

Thanks for the hint, but then why doesnt sveltekit produce a meaningful error message? This is cropping up again and again and it always takes a while until you figure out where its wrong.

dummdidumm commented 2 years ago

@bluwy I suspect this error is thrown by either vite or vps - is there a way to throw a different error there, something like "X is not a valid import from Y. If this is a type import, use the import type syntax." or sth like that?

bluwy commented 2 years ago

From the errors, looks like it's coming from Vite's dep scanner, which uses esbuild to process TS, and it tries to resolve @sveltejs/kit because it's not a type import. I guess we can add an extra heuristic where if it fails to resolve, it checks if there's a type condition and suggest that. But it would be a fair refactor before we can do that. I'll put this in my todo list 🙂

rolandm2017 commented 1 year ago

Does this have a fix yet? I get the same or a similar bug when I add import { error } from "@sveltejs/kit" to a svelte component

the bug states:

[vite] Internal server error: Failed to resolve entry for package "@sveltejs/kit". The package may have incorrect main/module/exports specified in its package.json: No known conditions for "." entry in "@sveltejs/kit" package

bluwy commented 1 year ago

I can't reproduce this anymore. The errors come around when you require('@sveltejs/kit'), because SvelteKit only exports with the import condition, not the require condition. This can happen when some tooling compiles the import you write, into a require, and sometimes that can happen because the package.json "type": "module" not set, maybe that's the case?

janosh commented 1 year ago

Haven't encountered this in a long time either.