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

JavaScript does not get loaded on the custom _error.js page #4231

Closed
1 task done
MatthiasMargot opened this issue Apr 30, 2018 · 10 comments
Closed
1 task done

JavaScript does not get loaded on the custom _error.js page #4231

MatthiasMargot opened this issue Apr 30, 2018 · 10 comments

Comments

@MatthiasMargot
Copy link

None of my JavaScript gets loaded on the custom _error page in a production bundle, works fine in development though.

There's also things on the _error page that are reused elsewhere in the application like a common header that has some JavaScript for letting a user log in/sign out.

In the console I can see some errors saying the scripts can't be found.
Is this normal behaviour that you simply can't run any JavaScript on the _error page? Is there any way to hack around this?

asdf:1 GET https://<BASE_URL>/_next/56777ac5-5382-4caf-9a49-e437db6e03a1/page/asdf.js net::ERR_ABORTED
  • I have searched the issues of this repository and believe that this is not a duplicate.

Steps to Reproduce (for bugs)

  1. Create a custom _error.js page in the pages folder that's part of next's api
  2. Go to a route that doesn't exist

Context

I was asked to implement a newsletter subscription form on the custom error page in order to give the user the ability to be notified as soon as a certain page exists because we have links that don't lead anywhere yet for a second stage of the project.

Your Environment

Tech Version
next 4.2.3
node 9.5.0
OS Mac OS X
Chrome 65.0.3325.181
@timneutkens
Copy link
Member

Try upgrading to Next 6

@timneutkens
Copy link
Member

Thanks for following the issue template perfectly 🙏

@MatthiasMargot
Copy link
Author

Is that the answer to this problem?
I'm currently on next 4.2.3, is that safe to just do?
Are you guys keeping complete backward compatibility?

@timneutkens
Copy link
Member

If you're not customizing .babelrc/next.config.js we're 100% backwards compatible with 4.2.3, otherwise you might have to make some changes.

@MatthiasMargot
Copy link
Author

Hi, getting back on this thread because I have tried migrating but I have customized next.config.js and .babelrc and when I tried migrating babel was giving me errors and I lost too much time trying to do that, so I eventually ignored this for a while. I would really like to find a solution to this that does not involve the migration.

A couple of things I can imagine but wouldn't know how to implement in next exactly:

  • Access to the status code of internal next mechanism from a custom routing middleware
  • Redirecting from the _error page via next/router (but that again would mean js would need to run, question: can you redirect with the next/router server-side and will that work inside say getInitialProps of the _error page?)

If all else fails, do you have a common issues migration guide with a customized .babelrc that states exactly what configurations/babel-syntax is not backward compatible?

I have tried debugging this but I'm getting errors I can't find mentioned on any other threads and it's gonna take me too long to fix this myself :/

@timneutkens
Copy link
Member

@MatthiasMargot can you post your .babelrc + the errors you're getting?

@MatthiasMargot
Copy link
Author

{
    "presets": [
        "next/babel", "flow"
    ],
    "plugins": [
        "inline-react-svg",
        "transform-flow-strip-types",
        ["babel-plugin-root-import",
            [
                {
                    "rootPathPrefix": "~"
                },
                {
                    "rootPathPrefix": "@",
                    "rootPathSuffix": "src/components"
                },
                {
                    "rootPathPrefix": "#",
                    "rootPathSuffix": "src/utils"
                }
            ]
        ],
        "babel-plugin-styled-components",
        ["styled-components", { 
            "ssr": true, 
            "displayName": true, 
            "preprocess": false }
        ],
        ["transform-define", "./env-config.js"]
    ]
}
UnhandledPromiseRejectionWarning: Error: .plugins[2][1] must be an object, false, or undefined

@timneutkens
Copy link
Member

The error is actually pretty clear,

["babel-plugin-root-import",
            [
                {
                    "rootPathPrefix": "~"
                },
                {
                    "rootPathPrefix": "@",
                    "rootPathSuffix": "src/components"
                },
                {
                    "rootPathPrefix": "#",
                    "rootPathSuffix": "src/utils"
                }
            ]
        ],

this must be an object. Seems like it's an open pull request here: entwicklerstube/babel-plugin-root-import#93

Also ["transform-define", "./env-config.js"] must be an object too, you can do this using .babelrc.js: #4239 (comment)

@billnbell
Copy link

Yeah we need to get that PR entwicklerstube/babel-plugin-root-import#93 approved.

@timneutkens
Copy link
Member

Going to close this as it works fine on latest.

@lock lock bot locked as resolved and limited conversation to collaborators Aug 3, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants