ConrabOpto / mst-query

Query library for mobx-state-tree
MIT License
110 stars 7 forks source link

How to use it with Nextjs? #17

Closed benjaminkwokhuen closed 2 years ago

benjaminkwokhuen commented 2 years ago

Got SyntaxError: Cannot use import statement outside a module

The module does not work in server side.

k-ode commented 2 years ago

This is becuase nextjs doesn't support es modules properly yet. See this thread and comment: https://github.com/vercel/next.js/issues/9890#issuecomment-968365119

The solution is to use next-transpile-modules in your next.config.js.

const withTM = require('next-transpile-modules')(['mst-query']);

module.exports = withTM({
  ... 
});
benjaminkwokhuen commented 2 years ago

@k-ode Thanks a lot. It works now.