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
[adapter-node] Cannot use import statement outside a module #2410
Comments
Editing the config with : adapter: adapter({
esbuild: (defaultConfig) => ({
...defaultConfig,
format: 'cjs'
})
}) Gives this error : node:internal/modules/cjs/loader:1214
throw new ERR_INVALID_ARG_VALUE('filename', filename,
^
TypeError [ERR_INVALID_ARG_VALUE]: The argument 'filename' must be a file URL object, file URL string, or absolute path string. Received undefined
at new NodeError (node:internal/errors:371:5)
at createRequire (node:internal/modules/cjs/loader:1214:13)
at node_modules/@sveltejs/adapter-node/files/shims.js (/var/www/vhosts/myhost/httpdocs/middlewares.js:1048:46)
at __init (/var/www/vhosts/myhost/httpdocs/middlewares.js:29:50)
at Object.<anonymous> (/var/www/vhosts/myhost/httpdocs/middlewares.js:16237:1)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
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 Module.require (node:internal/modules/cjs/loader:1005:19) {
code: 'ERR_INVALID_ARG_VALUE'
} The error is from : // node_modules/@sveltejs/adapter-node/files/shims.js
var import_module, import_meta;
var init_shims = __esm({
"node_modules/@sveltejs/adapter-node/files/shims.js"() {
import_module = __toModule(require("module"));
init_install_fetch();
import_meta = {};
Object.defineProperty(globalThis, "require", {
enumerable: true,
value: (0, import_module.createRequire)(import_meta.url)
});
}
}); |
I don't know if you have to or can specify a |
I tried it but it doesn't work. |
Searching around "Plesk + Node", looks like they have poor support for NodeJS versions and are generally outdated. Example. The minimum supported version by SvelteKit is |
I did upgrade to node 16 but doesn't still work. |
Is it node 16 in Plesk or locally? Based on your description, it looks like Plesk is having trouble running ESM code, as it's running it in CJS context, which shouldn't be the case if |
Both : I use node 16.9 in Plesk and locally. /usr/share/passenger/helper-scripts/node-loader.js:80
return originalRequire.apply(this, arguments);
^
Error [ERR_REQUIRE_ESM]: require() of ES Module /var/www/vhosts/mydomain/httpdocs/index.js from /usr/share/passenger/helper-scripts/node-loader.js not supported.
Instead change the require of index.js in /usr/share/passenger/helper-scripts/node-loader.js to a dynamic import() which is available in all CommonJS modules.
at Module.require (/usr/share/passenger/helper-scripts/node-loader.js:80:25)
at loadApplication (/usr/share/passenger/helper-scripts/node-loader.js:243:2)
at setupEnvironment (/usr/share/passenger/helper-scripts/node-loader.js:214:2)
at Object.<anonymous> (/usr/share/passenger/helper-scripts/node-loader.js:133:1) {
code: 'ERR_REQUIRE_ESM'
} |
Thanks for the info. Looking at the first line: |
Oh thank you @bluwy ! |
For information : https://talk.plesk.com/threads/nodejs-execute-esm-code.362146/ (no answers yet) |
Not sure if this helps, but I just had the same error when not deploying the Error when doing a FROM node
COPY build build
CMD ["node", "build"] All fine here: FROM node
COPY build build
COPY package.json package.json
CMD ["node", "build"] |
No, I don't think this is Plesk-specific. The docker setup just tells you that whenever you have a host where you have node installed and you only upload the |
Thanks for the clarification. Yeah the
It may be beneficial to note this under the node adapter readme. Feel free to send a PR! |
No problem. Makes also sense regarding the |
I had exactly the same issue on Plesk running Node 17.4.0, resolved by creating a {
"type": "module"
} And then pointing plesk towards an additional file ( (() => import('./index.js'))(); |
Great job, this worked for basic useage. Any idea how to fix that? |
Describe the bug
In local, the
build
with the node adapter works perfectly but when deploying it in Plesk I've got the message :Reproduction
Don't know what to give to you in order to reproduce that.
Logs
No response
System Info
Severity
blocking all usage of SvelteKit
Additional Information
No response
The text was updated successfully, but these errors were encountered: