question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

adapter-static fails with ESM config

See original GitHub issue
npm init svelte@next test-esm-static
cd test-esm-static
mv svelte.config.cjs svelte.config.js
yarn add -D @sveltejs/kit@next @sveltejs/adapter-static@next

and changing the contents of svelte.config.js to

import adapter from "@sveltejs/adapter-static";

export default {
  adapter: adapter(),
  kit: {
    target: "#svelte",
  },
};

followed by svelte-kit (dev|build) throws

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined in node_modules/@sveltejs/adapter-static/package.json imported from svelte.config.js
    at new NodeError (node:internal/errors:363:5)
    at throwExportsNotFound (node:internal/modules/esm/resolve:321:9)
    at packageExportsResolve (node:internal/modules/esm/resolve:510:7)
    at packageResolve (node:internal/modules/esm/resolve:687:14)
    at moduleResolve (node:internal/modules/esm/resolve:739:18)
    at Loader.defaultResolve [as _resolve] (node:internal/modules/esm/resolve:853:11)
    at Loader.resolve (node:internal/modules/esm/loader:89:40)
    at Loader.getModuleJob (node:internal/modules/esm/loader:242:28)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:73:40)
    at link (node:internal/modules/esm/module_job:72:36)

I was expecting this to work now that #936 is merged but looks like the adapters still need updating?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:24 (15 by maintainers)

github_iconTop GitHub Comments

2reactions
pikeascommented, May 4, 2021

I did try to re-write it with ESM, but it just spat out:

Malformed svelte.config.js
SyntaxError: Unexpected strict mode reserved word
    at Loader.moduleStrategy (internal/modules/esm/translators.js:145:18)
    at async link (internal/modules/esm/module_job.js:47:21)

Also no my global.css isn’t relative, I have it set to /global.css

Can you please share what your attempted ESM conversion looks like? It’s almost impossible for anybody to know what the issue is if we can’t see that file.

(By the way, we shouldn’t really even be having a support session in the GitHub issues – probably the Discord server instead).

Just bit by this myself. I had const static in the file, and static is a reserved word. Replace all reserved words in the file and hopefully everything will work.

Is there a reason for adapter-static to exist as a separate package, vs encouraging users to roll their own? For example:

/** @type {import('@sveltejs/kit').Adapter} */
const staticAdapter = {
    name: "local/adapter-static",

    async adapt(utils) {
        utils.copy_static_files("build")
        utils.copy_client_files("build")

        await utils.prerender({
            all: true,
            dest: "build",
            fallback: null,
        })
    },
}
1reaction
Rich-Harriscommented, May 3, 2021

That’s likely due to a bug in Svelte 3.38.0 and 3.38.1 — should be fixed in 3.38.2

Read more comments on GitHub >

github_iconTop Results From Across the Web

node.js - SvelteKit build throws ESM module error in ...
Tested with the standard SvelteKit demo app and addition of adapter-node in the config as per usual: import adapter from '@sveltejs/adapter-node ...
Read more >
@sveltejs/adapter-static | Yarn - Package Manager
Adapter for SvelteKit apps that prerenders your entire site as a collection of static files. If you'd like to prerender only some pages,...
Read more >
ECMAScript Modules - Jest
Jest ships with experimental support for ECMAScript Modules (ESM). The implementation may have bugs and lack features. For the latest status ...
Read more >
: unknown file extension ".ts" | The AI Search Engine You Control
I'm having the same issue. λ npx ts-node src/app.ts TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for C:\Users\$USER ...
Read more >
[ERR_MODULE_NOT_FOUND] Cannot find module ... - Reddit
Using @sveltejs/adapter-static > Cannot find module ... Did you mean to import @popperjs/core/dist/esm/popper.js? Error ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found