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

adapter-vercel: Use CJS entrypoint to load ESM files #483

Merged
merged 7 commits into from
Mar 12, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/selfish-owls-own.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/adapter-vercel': patch
---

Fix mixed usage of CJS and ESM
2 changes: 1 addition & 1 deletion packages/adapter-vercel/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ export default {
exports: 'default'
},
plugins: [nodeResolve(), commonjs()],
external: require('module').builtinModules
external: [...require('module').builtinModules, './server/app.js']
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this need to use path.join in order to work cross-platform?

Copy link
Member Author

@GrygrFlzr GrygrFlzr Mar 11, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, I built the adapter on Windows, and it properly recognizes it as an external dependency.

};
9 changes: 5 additions & 4 deletions packages/adapter-vercel/src/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { parse, URLSearchParams } from 'url';
import { URL, URLSearchParams } from 'url';
import { get_body } from '@sveltejs/app-utils/http';

const app = require('./server/app.js');

export default async (req, res) => {
const { pathname, query = '' } = parse(req.url || '');
const host = `${req.headers['x-forwarded-proto']}://${req.headers.host}`;
const { pathname, query = '' } = new URL(req.url || '', host);

const { default: app } = await import('./server/app.js');

const rendered = await app.render({
method: req.method,
Expand Down