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

Syntax error in cjs code for netlify-adapter can break deploys #3526

Closed
goynang opened this issue Jan 24, 2022 · 0 comments · Fixed by #3546
Closed

Syntax error in cjs code for netlify-adapter can break deploys #3526

goynang opened this issue Jan 24, 2022 · 0 comments · Fixed by #3546
Labels
bug Something isn't working pkg:adapter-netlify
Milestone

Comments

@goynang
Copy link

goynang commented Jan 24, 2022

There is an error in the CJS code generated for netlify-adapter where line 6 of .netlify/handler.js ends up as...

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

...which is a syntax error and leads to bad deploy unless you force esbuild to be used instead. The CJS version of handler.js (before code replacements take place) looks like...

var APP = require('APP');

...whereas the ESM version looks like...

import { App } from 'APP';

The code substitution is based on replacing APP with ./server/app.js (lines 53-55 of adapter-netlify/index.js) so mistakenly replaces both uses within the require statement (the variable and the path).

It looks like rollup is altering the import from App to APP when it changes it to a require statement for CJS.

In addition it looks like the adapter is hardcoded to build CJS functions targeted for node 12...

const output = esbuild.transformSync(input, { format: 'cjs', target: 'node12' }).code;

...rather than something newer or respecting netlify.toml

Originally posted by @goynang in #2687 (comment)

@benmccann benmccann added bug Something isn't working pkg:adapter-netlify labels Jan 24, 2022
@benmccann benmccann added this to the 1.0 milestone Jan 24, 2022
Rich-Harris added a commit that referenced this issue Jan 26, 2022
* give module id an invalid name to prevent invalid replacement - fixes #3526

* changeset

* Update packages/adapter-netlify/index.js

* Update packages/adapter-netlify/index.js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working pkg:adapter-netlify
Projects
None yet
2 participants