-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Error with custom entryPoint in adapter-node #2481
Comments
The generated @benmccann As the author of #2414, do you have any ideas? |
If I update the regex at kit/packages/adapter-node/index.js Line 94 in b781b2f
/middlewares.js as external, this appears to work, but that's too heavy-handed of a solution. I'm not sure exactly what this is trying to work around, but apparently something is passing a different path to this onResolve hook.
|
The only thing I did in #2414 was let you modify the entry point. I'm not familiar with esbuild at all, so don't know what all this other stuff is about |
Proof-of-concept solution (I think): diff --git a/packages/adapter-node/index.js b/packages/adapter-node/index.js
index cc2dd47d..4bc9e805 100644
--- a/packages/adapter-node/index.js
+++ b/packages/adapter-node/index.js
@@ -7,7 +7,7 @@ import {
statSync,
writeFileSync
} from 'fs';
-import { join } from 'path';
+import { join, resolve } from 'path';
import { pipeline } from 'stream';
import glob from 'tiny-glob';
import { fileURLToPath } from 'url';
@@ -81,7 +81,6 @@ export default function ({
entryPoints: [entryPoint],
outfile: join(out, 'index.js'),
bundle: true,
- external: ['./middlewares.js'], // does not work, eslint does not exclude middlewares from target
format: 'esm',
platform: 'node',
target: 'node12',
@@ -90,8 +89,12 @@ export default function ({
{
name: 'fix-middlewares-exclude',
setup(build) {
- // Match an import called "./middlewares.js" and mark it as external
- build.onResolve({ filter: /^\.\/middlewares\.js$/ }, () => ({ external: true }));
+ // Match an import of "middlewares.js" and mark it as external
+ build.onResolve({ filter: /\/middlewares\.js$/ }, ({ path, resolveDir }) => {
+ if (resolve(resolveDir, path) === resolve(out, 'middlewares.js')) {
+ return { external: true };
+ }
+ });
}
}
] This uses a regex to filter out just import paths ending in If I'm understanding esbuild's architecture correctly, the regex gets turned into a Go regex, and we only have to hop over into JS when it's matched. So, it's worthwhile to try to filter out as much as possible in the regex, rather than in the JS callback. |
I'm not wild about the {
path: '../build/middlewares.js',
importer: '/some/path/sveltekit-adapter-node-bug-repro/src/server.js',
namespace: 'file',
resolveDir: '/some/path/sveltekit-adapter-node-bug-repro/src',
kind: 'import-statement',
pluginData: undefined
} |
@oskarhane Did you solve your issue? I'm having the exact same issue while deploying on Fly.io, that is I'm using @Conduitry Could it be your fix is no more working since the latest changes? |
Describe the bug
When setting up adapter-node I'm configuring a custom entry point copied from the example here: https://github.com/sveltejs/kit/tree/master/packages/adapter-node#middleware but I run into this error when I try to start the server with
node build
:Dynamic require of "buffer" is not supported
.The error message points to the
jsonwebtoken
package which I use on some node only endpoints.But, this is not specific to this package, it's the same with
dotenv
and other node packages.If I skip the entryPoint config in the adapter setup, it works.
Reproduction
Minimal repro repo: https://github.com/oskarhane/sveltekit-adapter-node-bug-repro
All I've done there is to
npm init svelte@next
, installing@sveltejs/adapter-node
,jsonwebtoken
andpolka
and configured the adapter after creating a single request handler that uses the jwt package.Edit (toggle the comments) the adapter config in
svelte.config.js
and try again to have it work / not work.Logs
System Info
Severity
blocking all usage of SvelteKit
Additional Information
No response
The text was updated successfully, but these errors were encountered: