sveltejs / kit

web development, streamlined
https://svelte.dev/docs/kit
MIT License
18.69k stars 1.93k forks source link

Unable to use this adapter : No "exports" main defined in ...@sveltejs\adapter-static\package.json #1411

Closed dsmtE closed 3 years ago

dsmtE commented 3 years ago

I am trying to use this adapter within my project, but I encounter this issue:

No "exports" main defined in D:\(...)\node_modules\@sveltejs\adapter-static\package.json
Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined in D:\(...)\node_modules\@sveltejs\adapter-static\package.json
    at throwExportsNotFound (internal/modules/esm/resolve.js:290:9)
    at packageExportsResolve (internal/modules/esm/resolve.js:479:7)
    at resolveExports (internal/modules/cjs/loader.js:432:36)
    at Function.Module._findPath (internal/modules/cjs/loader.js:472:31)
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:867:27)
    at Function.Module._load (internal/modules/cjs/loader.js:725:27)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Object.<anonymous> (D:\(...)\svelte.config.cjs:4:16)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)

(...) is an alias here for the root folder

my svelte.config.cjs :

const { mdsvex } = require("mdsvex");
const mdsvexConfig = require("./mdsvex.config.cjs");
const sveltePreprocess = require('svelte-preprocess');
const static = require('@sveltejs/adapter-static');

/** @type {import('@sveltejs/kit').Config} */
module.exports = {
    extensions: [".svelte", ...mdsvexConfig.extensions],
    // Consult https://github.com/sveltejs/svelte-preprocess
    // for more information about preprocessors
    preprocess: [
        mdsvex(mdsvexConfig),
        sveltePreprocess({
          defaults: {
            style: 'postcss',
          },
          postcss: true,
        }),
      ],

    kit: {
        // By default, `npm run build` will create a standard Node app.
        // You can create optimized builds for different platforms by
        // specifying a different adapter
        adapter: static(),
        // hydrate the <div id="svelte"> element in src/app.html
        target: '#svelte'
    }
};

Could you help my ? Thanks in advance.

Conduitry commented 3 years ago

As of version next.97 of Kit and next.8 of the static adapter, you need to use ESM configuration files and imports for the adapters instead of requires.

lsabi commented 3 years ago

If anyone bumps into this problem, here's the example of how the config should look like

https://kit.svelte.dev/docs#configuration

autr commented 3 years ago

Not as simple as copying the config - as everything is in flux, sometimes the adapter@next goes out of sync with kit@next. Use:

pnpm view @sveltejs/kit versions
pnpm view @sveltejs/adapter-static versions

To view what's available. For example adapter-static@1.0.0-next.9 and kit@1.0.0-next.107 and reformatting svelte.config.js worked for me.

yaeszlo commented 3 years ago

Had the same error just a moment ago and no solutions helped, but turned out I installed the dependency not as dev dependency. Moved it and now works fine.