Skip to content

dynamic imports not working with typescript #3389

@johhansantana

Description

@johhansantana

I'm getting this error message:

`next/dynamic` options should contain `modules` and `render` fields

Here's my code:

import dynamic from 'next/dynamic'
const RoutesMap = dynamic(import("./components/routesMap"), {
  ssr: false
})
// routesMap
import * as React from 'react'
class RoutesMap extends React.Component {

  render() {
    return (
      <div>
        <p>hello</p>
      </div>
    )
  }
}

export default RoutesMap

this gets compiled via typescript and the result is this:

const RoutesMap = dynamic_1.default(Promise.resolve().then(() => require('./components/routesMap')), { ssr: false });

and if I use

import * as dynamic from 'next/dynamic'

I get:

dynamic is not a function

tsconfig:

{
  "compilerOptions": {
    "module": "commonjs",
    "target": "es2015",
    "jsx": "react-native",
    "allowJs": true,
    "baseUrl": ".",
    "paths": {
      "!/*": [
        "./*"
      ]
    },
    "lib": [
      "es5",
      "es6",
      "dom",
      "es2015.core",
      "es2015.collection",
      "es2015.generator",
      "es2015.iterable",
      "es2015.promise",
      "es2015.proxy",
      "es2015.reflect",
      "es2015.symbol",
      "es2015.symbol.wellknown",
      "esnext.asynciterable"
    ]
  }
}
"next": "^4.1.4",
"react": "^16.2.0",
"react-dom": "^16.2.0"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions