Natasha
Natasha

Reputation: 766

Issue with next.js/typescript/webpack: "Unhandled Rejection (ReferenceError): XYZ is not defined"

Please find below three files of a demo next.js/TypeScript project. Please be aware that SomeType.tshas a TS type as default export and some-stuff.ts has a TS type and a JS object as exports. I think this should work, but instead I get the following error message - does anyone know what could be the problem?

error message


pages/SomeType.ts:

  type SomeType = { a: number, b: number }

  export default SomeType

pages/some-stuff.ts:

  import SomeType from './SomeType'

  const someValue: SomeType = { a: 11, b: 22 }

  export {
    someValue,

    // If we would not export SomeType
    // the demo would work fine - very strange...
    SomeType
  }

pages/index.ts

  import { someValue } from './some-stuff'

  export default () => JSON.stringify(someValue)

Upvotes: 1

Views: 183

Answers (1)

evgeni fotia
evgeni fotia

Reputation: 4810

Try using webpack version 4.28.2 ` here is the GitHub issue

Also change export default SomeType to export { SomeType } and import SomeType from './SomeType' to import { SomeType } from './SomeType'

Upvotes: 1

Related Questions