kit: [adapter-node] Cannot use import statement outside a module
Describe the bug
In local, the build
with the node adapter works perfectly but when deploying it in Plesk I’ve got the message :
import { assetsMiddleware, kitMiddleware, prerenderedMiddleware } from "./middlewares.mjs";
^^^^^^
SyntaxError: Cannot use import statement outside a module
at Object.compileFunction (node:vm:352:18)
at wrapSafe (node:internal/modules/cjs/loader:1031:15)
at Module._compile (node:internal/modules/cjs/loader:1065:27)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:79:12)
at node:internal/main/run_main_module:17:47
Reproduction
Don’t know what to give to you in order to reproduce that.
Logs
No response
System Info
System:
OS: Linux 5.4 Ubuntu 20.04.3 LTS (Focal Fossa)
CPU: (4) x64 Intel(R) Xeon(R) Gold 6230R CPU @ 2.10GHz
Memory: 191.33 MB / 7.75 GB
Container: Yes
Shell: 5.0.17 - /bin/bash
Binaries:
Node: 16.9.1 - /usr/bin/node
npm: 7.21.1 - /usr/bin/npm
Severity
blocking all usage of SvelteKit
Additional Information
No response
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 1
- Comments: 17 (10 by maintainers)
I had exactly the same issue on Plesk running Node 17.4.0, resolved by creating a
package.json
in the build output thus:And then pointing plesk towards an additional file (
index.cjs
) added to the build output thus:Not sure if this helps, but I just had the same error when not deploying the
package.json
along thebuild
directory. I think it would be nice to document this.Error when doing a
docker build
anddocker run
on this:All fine here:
No problem. Makes also sense regarding the
{"type": "module"}
it brings and the error message. I added a small PR for the README.Oh thank you @bluwy ! I will search there and if I found a solution, I will post it here
Both : I use node 16.9 in Plesk and locally. When I add the
package.json
with the"type": "module"
info, I’ve got this error :