next.js: Fetch API cannot load webpack://%5Bname%5D_%5Bchunkhash%5D/ CORS

Bug report

Describe the bug

Cannot fetch <script src="..."/> on client successfully, encountering CORS webpack issue

VM704:1 Fetch API cannot load webpack://%5Bname%5D_%5Bchunkhash%5D/./node_modules/react-dom/cjs/react-dom.development.js?. URL scheme must be "http" or "https" for CORS request.

To Reproduce

Repo: https://github.com/notJackson/nextjs-webpack-cors-issue

Expected behavior

Run script on client

Screenshots

If applicable, add screenshots to help explain your problem.

System information

  • OS: Ubuntu 18.04.1 LTS
  • Browser: Chromium Version 72.0.3626.96 (Official Build) snap (64-bit)
  • Project dependencies:
    "next": "^8.0.1",
    "react": "^16.8.2",
    "react-dom": "^16.8.2",
    "react-runkit": "^0.9.0"

Additional context

Related discussion on spectrum: https://spectrum.chat/next-js/general/upgrade-guide-from-next-6-x-to-next-7~3e83c1c4-419d-4497-b9e2-9a927cd3562b?m=MTUzNzQ2MDgxOTg1OQ==

Not relying on this to work, but figured since I already had a minimal repro repo I might as well publish this so one can eventually look into this.

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 21
  • Comments: 23 (8 by maintainers)

Most upvoted comments

Sorry to re-wake this thread but has this actually been resolved? I’m still coming up against this issue, which doesn’t seem to be resolved. However it seems to be an issue that comes up and is closed, but I don’t feel that I understand what I am supposed to do about it — or even if I need to worry about it, since my app seems to be running fine.

https://github.com/vercel/next.js/discussions/14219, https://github.com/vercel/next.js/issues/10086, https://github.com/vercel/next.js/issues/9680, https://github.com/vercel/next.js/issues/6374

I am getting this issue while trying to work with the with-sentry example in my app as soon as I try to generate an error.

Since the comments here suggested react-error-overlay could be an issue, I tried to run my code in production mode and it worked fine. Please let me know if I need to provide some other details.

Sounds like a bug in react-error-overlay 🕵️

I can confirm that react-error-overlay causes this (atleast with my project), I’ve attempted to read a field from undefined in getInitialProps and instead of getting a useful error message the whole thing crashed with Fetch API cannot load webpack://%5Bname%5D_%5Bchunkhash%5D .....

Hope this helps

I encountered the bug while integrating react-datepicker and formik.

Here is a repo for the minimal reproducible case.

To reproduce the error, start the dev server and choose a day on the datepicker.

Here is the meat of the repo:

//next.config.js
const withCSS = require('@zeit/next-css');
module.exports = withCSS();

package.json

{
  "dependencies": {
    "@zeit/next-css": "^1.0.1",
    "formik": "^1.5.1",
    "next": "^8.0.3",
    "react": "^16.8.4",
    "react-datepicker": "^2.2.0",
    "react-dom": "^16.8.4"
  },
  "scripts": {
    "dev": "next",
    "build": "next build",
    "start": "next start"
  }
}

and

// ./pages/index.js
import React from 'react'
import {Formik, Form, Field} from 'formik';
import DatePicker from "react-datepicker";
import "react-datepicker/dist/react-datepicker.css";


export const DateField = ( {field} ) => (
    <DatePicker
        selected={field.value}
        onChange={field.onChange}
        id={field.name}
    />
);

class IndexPage extends React.Component {
    render() {
        return (
            <Formik
                initialValues={{scheduleTime: null}}
                onSubmit={(values) => {
                    console.log(values);
                }}
            >
                {() => {
                    return (
                        <Form>
                            <Field name="scheduleTime" component={DateField}/>
                            <button type='submit'>Submit Form</button>
                        </Form>
                    )
                }}
            </Formik>
        )
    }
}

export default IndexPage

Hmm…well I got it to work, but in a weird way that I think gets around this bug, but reinforces my belief that it may have something to do with next.js. Now, rather than append to an array in my setState I simply set the state to a concatenated string (see here: https://gist.github.com/patientplatypus/1857c5e30d89d2f399591acb9d56a574). My problem is definitely solved, ijjk and I appreciate the offer for support. I would suggest making a note that maybe it has something to do with setState? And also there are of course still other people with issues.

Thanks again for the suggestions guys.

Sounds like a bug in react-error-overlay 🕵️

This didn’t close the issue for me. Please consider reopening.