Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Malformed svelte.config.js #1630

Closed
mylastore opened this issue Jun 2, 2021 · 10 comments
Closed

Malformed svelte.config.js #1630

mylastore opened this issue Jun 2, 2021 · 10 comments

Comments

@mylastore
Copy link

mylastore commented Jun 2, 2021

updated today to latest sveltekit and adapter node see below and using example configuration listed on sveltekit documentation and I am using node adapter as you can see.

    import node from '@sveltejs/adapter-node'
	kit: {
		adapter: node(),

  "@sveltejs/adapter-node": "^1.0.0-next.0",
  "@sveltejs/kit": "^1.0.0-next.1",

now getting this error:

Malformed svelte.config.js
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /mnt/Backup/sys/now/svelte-kit/svelte.config.js
require() of ES modules is not supported.
require() of /mnt/Backup/sys/now/svelte-kit/svelte.config.js from /mnt/Backup/sys/now/svelte-kit/@root 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 svelte.config.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /mnt/Backup/sys/now/svelte-kit/package.json.

    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1080:13)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at relative (/mnt/Backup/sys/now/svelte-kit/node_modules/node_modules/.pnpm/require-relative@0.8.7/node_modules/require-relative/index.js:25:15)
    at Object.load_config (/mnt/Backup/sys/now/svelte-kit/node_modules/@sveltejs/kit/src/api/load_config/index.js:15:17)
    at Object.<anonymous> (/mnt/Backup/sys/now/svelte-kit/node_modules/@sveltejs/kit/src/cli.js:9:11)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! my-la-store@0.0.2 start: `svelte-kit dev`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the my-la-store@0.0.2 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/oscar/.npm/_logs/2021-06-02T22_04_48_388Z-debug.log
oscar@oscar-Inspiron-3847:/mnt/Backup/sys/now/svelte-kit$ npm start

> my-la-store@0.0.2 start /mnt/Backup/sys/now/svelte-kit
> svelte-kit dev
@Conduitry
Copy link
Member

This sounds like maybe #1618. From those error messages, it's definitely not the latest version of Kit getting used somewhere.

@mylastore
Copy link
Author

mylastore commented Jun 2, 2021

This sounds like maybe #1618. From those error messages, it's definitely not the latest version of Kit getting used somewhere.

updated to "@sveltejs/kit": "^1.0.0-next.113" and I am pass the original error on this issue, but a new one was generated see below. At least the app is running (who knows for how long :) )

(node:32450) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'copy_server_files' of undefined
    at adapter (/mnt/Backup/sys/now/svelte-kit/node_modules/@sveltejs/adapter-node/index.js:8:10)
    at file:///mnt/Backup/sys/now/svelte-kit/svelte.config.js:13:11
    at ModuleJob.run (internal/modules/esm/module_job.js:152:23)
    at async Loader.import (internal/modules/esm/loader.js:166:24)
    at async load_config (file:///mnt/Backup/sys/now/svelte-kit/node_modules/@sveltejs/kit/dist/cli.js:502:17)
    at async get_config (file:///mnt/Backup/sys/now/svelte-kit/node_modules/@sveltejs/kit/dist/cli.js:557:10)
    at async file:///mnt/Backup/sys/now/svelte-kit/node_modules/@sveltejs/kit/dist/cli.js:615:18
(Use `node --trace-warnings ...` to show where the warning was created)
(node:32450) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:32450) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit cod

@mylastore
Copy link
Author

mylastore commented Jun 2, 2021

This sounds like maybe #1618. From those error messages, it's definitely not the latest version of Kit getting used somewhere.

updated to "@sveltejs/kit": "^1.0.0-next.113" and I am pass the original error on this issue, but a new one was generated see below. At least the app is running (who knows for how long :) )

(node:32450) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'copy_server_files' of undefined
    at adapter (/mnt/Backup/sys/now/svelte-kit/node_modules/@sveltejs/adapter-node/index.js:8:10)
    at file:///mnt/Backup/sys/now/svelte-kit/svelte.config.js:13:11

This fixed this issue

import node from '@sveltejs/adapter-node'
	kit: {
		adapter: {
			adapt: async () => await node()
		},
}

@benmccann
Copy link
Member

Ok. I'll go ahead and close this since it sounds like the issue is fixed now

@shlomocarmeter
Copy link

@benmccann
Can you please update this on the docs?

import node from '@sveltejs/adapter-node'
kit: {
adapter: {
adapt: async () => await node()
},
}

Thanks

@benmccann
Copy link
Member

The adapter isn't async: https://github.com/sveltejs/kit/blob/master/packages/adapter-node/index.js

That shouldn't be necessary. I just tested on my project and don't need to do it. Can you provide a repo where it is necessary?

@shlomocarmeter
Copy link

shlomocarmeter commented Jul 8, 2021

@benmccann
I have a private repo I'm currently working on,
when I try to set svelte.config.js like so:

import node from '@sveltejs/adapter-node';
import preprocess from 'svelte-preprocess';
/** @type {import('@sveltejs/kit').Config} */
const config = {
    kit: {
        adapter: node(),
     },
    preprocess: [
        preprocess({
            postcss: true,
        }),
    ],
    kit: {
        // hydrate the <div id="svelte"> element in src/app.html
         target: '#svelte',
     },
 };
 
export default config;

I get this:

> TODO@0.0.1 build
> svelte-kit build

/sveltekit/node_modules/@sveltejs/adapter-node/index.js:8
builder.copy_server_files(out);
^

TypeError: Cannot read property 'copy_server_files' of undefined
at adapter (/sveltekit/node_modules/@sveltejs/adapter-node/index.js:8:10)
at file:///sveltekit/svelte.config.js:6:18
at ModuleJob.run (node:internal/modules/esm/module_job:154:23)
at async Loader.import (node:internal/modules/esm/loader:177:24)
at async load_config (file:///sveltekit/node_modules/@sveltejs/kit/dist/cli.js:440:17)
at async get_config (file:///sveltekit/node_modules/@sveltejs/kit/dist/cli.js:495:10)
at async file:///sveltekit/node_modules/@sveltejs/kit/dist/cli.js:580:18
Press return ...

But if I use:

adapter: {
adapt: async () => await node(),
},

as @mylastore wrote in his last comment everything works.

@benmccann
Copy link
Member

That's not enough info to reproduce. I have basically the same exact config and don't get the error you're talking about. I think you probably have an outdated dependency or something, but can't tell from the info here

@shlomocarmeter
Copy link

I'll try to update and see how it goes.
Thanks

@mylastore
Copy link
Author

The issue is that you need to move almost all devDependencies to dependencies and that work for me specifically when you deployed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants