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

Doesn't recognize next.config.mjs #107

Closed
pratv1 opened this issue Nov 11, 2023 · 8 comments · Fixed by #139
Closed

Doesn't recognize next.config.mjs #107

pratv1 opened this issue Nov 11, 2023 · 8 comments · Fixed by #139
Assignees

Comments

@pratv1
Copy link

pratv1 commented Nov 11, 2023

It works fine with the js extension:

Run actions/configure-pages@v3
  with:
    static_site_generator: next
Injecting property=basePath and value= in:
/** @type {import('next').NextConfig} */
const nextConfig = {
  output: "export",
};

...but when I have a next.config.mjs, it ignores it and makes up a new config file on its own:

Run actions/configure-pages@v3
  with:
    static_site_generator: next
Using default blank configuration
Injecting property=basePath and value= in:
// Default Pages configuration for Next
const nextConfig = {}
module.exports = nextConfig
@2chanhaeng
Copy link

2chanhaeng commented Mar 5, 2024

I had a similar problem to yours for a similar reason.
Recently, when I create a project with create-next-app, it generates next.config.mjs instead of next.config.js.
So I think this issue could be going bigger and should be fixed sooner rather than later.
Additionally, I temporarily fixed the issue by deleting next.config.js just before the build like following:

      - name: Build with Next.js
        run: |
          rm -f next.config.js
          ${{ steps.detect-package-manager.outputs.runner }} next build

@OtmaniCodes
Copy link

is a solution found to this issue?

@pratv1
Copy link
Author

pratv1 commented Mar 17, 2024

@OtmaniCodes I ended up commenting out this line from the build step to make it work:

image

You can check my workflow file for reference.

@OtmaniCodes
Copy link

@OtmaniCodes I ended up commenting out this line from the build step to make it work:

image

You can check my workflow file for reference.

Thank you

@JamesMGreene JamesMGreene self-assigned this Mar 27, 2024
@JamesMGreene
Copy link
Contributor

JamesMGreene commented Mar 27, 2024

The available workaround is to provide the path in your Actions workflow via the generator_config_file input parameter, e.g.:

- name: Setup Pages
  uses: actions/configure-pages@v4
  with:
    static_site_generator: next
    generator_config_file: ./next.config.mjs

For now, I'll leave this issue open to look at auto-detecting alternative file paths. It's not something we'd prioritize highly, but it isn't an unreasonable expectation given the behind-the-scenes magic this action is already attempting to take care of on users' behalf. 🤷

@JamesMGreene
Copy link
Contributor

JamesMGreene commented Mar 30, 2024

A fix for this is now included in actions/configure-pages@v5. 🚀

e.g.

- name: Setup Pages
  uses: actions/configure-pages@v5
  with:
    static_site_generator: next

@imbirdperson
Copy link

I'm still getting the error after tyring all the above solutions. I'm new to JavaScript world. Can some one help me identify the problem. Below is the github action error. But I'm able to build the page locally without any errors.

'''Run actions/configure-pages@v5
Injecting property=output and value=export in:
import { createRequire } from "module";
const require = createRequire(import.meta.url);
const withMDX = require('@next/mdx')({
extension: /.mdx?$/,
});

/** @type {import('next').NextConfig} */
const nextConfig = {
output:'export',
distDir:'dist',
images:{
unoptimized: true,
},

pageExtensions: ['js', 'jsx', 'mdx', 'ts', 'tsx'],

};

export default withMDX(nextConfig);

Error: TypeError: error must be an instance of Error'''

@richardtorres314
Copy link

A fix for this is now included in actions/configure-pages@v5. 🚀

e.g.

- name: Setup Pages
  uses: actions/configure-pages@v5
  with:
    static_site_generator: next

@JamesMGreene The fix works well when there's no import, but seems to break when importing a dependency (or at least the @next/bundle-analyzer as I've tried). For example, in a next.config.mjs file:

// @ts-check

import NextBundleAnalyzer from '@next/bundle-analyzer';

const withBundleAnalyzer = NextBundleAnalyzer({
  enabled: process.env.ANALYZE === "true",
});

/** @type {import('next').NextConfig} */
const nextConfig = {
 output: "export"
};

export default withBundleAnalyzer(nextConfig);

results in the configure-pages action erroring out with the message, "TypeError: error must be an instance of Error".

Commenting the static_site_generator: next line seems to resolve the type error.

A minor inconvenience, but a workaround suffices. Glad to see the project continued adoption!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants