Skip to content

Expose contents of @sveltejs/app-utils as CJS as well as ESM #592

Closed
@antony

Description

@antony

Opening this for feedback before I go ahead and add the build step, but it looks like we can't use commonjs in adapters and then depend on esm modules such as @sveltejs/app-utils if we expect anything to work.

This sort of thing:

const { copy } = require('@sveltejs/app-utils/files');

relies on the exports map present in @sveltejs/app-utils:

"exports": {
		"./files": {
			"import": "./files/index.js"
		},
		"./http": {
			"import": "./http/index.js"
		}
	},

However this needs to be modified to allow require to access these exports too:

"exports": {
		"./files": {
			"import": "./files/index.js",
                        "require": "./files/index.js"
		},
		...
	},

This then causes the following error:

Must use import to load ES Module: /home/ant/Projects/kezia.ws/adapter/node_modules/@sveltejs/app-utils/files/index.js
require() of ES modules is not supported.
require() of /home/ant/Projects/kezia.ws/adapter/node_modules/@sveltejs/app-utils/files/index.js from /home/ant/Projects/kezia.ws/adapter/index.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename /home/ant/Projects/kezia.ws/adapter/node_modules/@sveltejs/app-utils/files/index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /home/ant/Projects/kezia.ws/adapter/node_modules/@sveltejs/app-utils/package.json.

So it looks like we need to build app-utils for cjs and esm in order that it can be used with both types of module.

Happy to go ahead and do this and then fix the vercel and begin adapters accordingly if I'm not missing something.

Metadata

Metadata

Assignees

No one assigned

    Labels

    adapters - generalSupport for functionality general to all adapters

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions