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

Failed to compile #20626

Closed
taoqf opened this issue Dec 31, 2020 · 3 comments · Fixed by #32702
Closed

Failed to compile #20626

taoqf opened this issue Dec 31, 2020 · 3 comments · Fixed by #32702
Labels
SWC Related to minification/transpilation in Next.js. Webpack Related to Webpack with Next.js.
Milestone

Comments

@taoqf
Copy link

taoqf commented Dec 31, 2020

Bug report

Describe the bug

A clear and concise description of what the bug is.

Error: xxx:Invalid page config export found. Expected object but got TSAsExpression in file /src/pages/index.tsx. See: https://err.sh/vercel/next.js/invalid-page-config

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

  1. Create page index.tsx
  2. Add page component.
  3. Add page config like this:
import { PageConfig } from 'next';
export const config = {
} as PageConfig;
  1. See error
  2. Change the config to:
export const config: PageConfig = {
};
  1. Error is gone.

Expected behavior

A clear and concise description of what you expected to happen.

Screenshots

If applicable, add screenshots to help explain your problem.

System information

  • OS: Debian
  • Browser (if applies) Chromium
  • Version of Next.js: 10.0.4
  • Version of Node.js: 15.5.0
  • Develop: next dev
  • TypeScript:4.1.3

Additional context

Add any other context about the problem here.

@taoqf taoqf added the bug Issue was opened via the bug report template. label Dec 31, 2020
@lachlanjc
Copy link
Contributor

I don't know how Typescript is playing into this, but the error mentions that the config object can't be dynamically modified: https://github.com/vercel/next.js/blob/master/errors/invalid-page-config.md#possible-ways-to-fix-it

@Timer Timer added kind: bug and removed bug Issue was opened via the bug report template. labels Jan 1, 2021
@Timer Timer modified the milestone: 10.x.x Jan 1, 2021
@taoqf
Copy link
Author

taoqf commented Jan 2, 2021

I tried compile them with ts, and the compiled js is exactly same.

a.ts

import { PageConfig } from 'next';

export const config = {
} as PageConfig;

b.ts

import { PageConfig } from 'next';

export const config: PageConfig = {
};

a.js

"use strict";
exports.__esModule = true;
exports.config = void 0;
exports.config = {};

b.js

"use strict";
exports.__esModule = true;
exports.config = void 0;
exports.config = {};

@timneutkens timneutkens added this to the 10.x.x milestone Jan 3, 2021
@Timer Timer modified the milestones: 10.x.x, backlog Jan 6, 2021
@timneutkens timneutkens added Webpack Related to Webpack with Next.js. SWC Related to minification/transpilation in Next.js. labels Nov 17, 2021
@kodiakhq kodiakhq bot closed this as completed in #32702 Feb 5, 2022
kodiakhq bot pushed a commit that referenced this issue Feb 5, 2022
fixes #20626

No changes needed in next-swc, see comments from @kdy1 below.

Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
natew pushed a commit to natew/next.js that referenced this issue Feb 16, 2022
…#32702)

fixes vercel#20626

No changes needed in next-swc, see comments from @kdy1 below.

Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
@github-actions
Copy link
Contributor

github-actions bot commented Mar 8, 2022

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 8, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
SWC Related to minification/transpilation in Next.js. Webpack Related to Webpack with Next.js.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants