question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
timneutkenscommented, May 11, 2018

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: https://github.com/entwicklerstube/babel-plugin-root-import/pull/93

Also ["transform-define", "./env-config.js"] must be an object too, you can do this using .babelrc.js: https://github.com/zeit/next.js/issues/4239#issuecomment-385775369

0reactions
timneutkenscommented, Aug 3, 2018

Going to close this as it works fine on latest.

Read more comments on GitHub >

github_iconTop Results From Across the Web

JavaScript does not get loaded on the custom _error.js page
None of my JavaScript gets loaded on the custom _error page in a production bundle, works fine in development though.
Read more >
How do I create a custom Error in JavaScript? - Stack Overflow
This confirmes the "problem" I ran into was the stack property of the error was the line number where new Error() was created,...
Read more >
Custom errors, extending Error - The Modern JavaScript Tutorial
JavaScript allows to use throw with any argument, so technically our custom error classes don't need to inherit from Error .
Read more >
A Definitive Guide to Handling Errors in JavaScript - Kinsta
Getting tripped up by errors in your JavaScript? We'll show you how to tame those errors so you can get back to developing...
Read more >
Creating Custom Errors in JavaScript - YouTube
Did you know that you can create your own custom Error objects in JavaScript ? This can be accomplished with both the older...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found