Mobx-state-tree: types.identifier is not a function with Babel 7

Created on 6 Oct 2018  路  2Comments  路  Source: mobxjs/mobx-state-tree

I have:

  • [ ] A conceptual question.

    • [ ] I've checked documentation and searched for existing issues

    • [ ] I tried the spectrum channel first

  • [x] I think something is not working as it should.

    • [x] I've checked documentation and searched for existing issues

    • [x] I've made sure your project is based on the latest MST version

    • [ ] Fork this code sandbox or another minimal reproduction.

    • [ ] Describe expected behavior

    • [ ] Describe observed behavior

  • [ ] Feature request

    • [ ] Describe the feature and why you feel your feature needs to be generically solved inside MST

    • [ ] Are you willing to (attempt) a PR?

I'm trying to upgrade Next.js to version 7, but MST is causing an issue. I'm using custom-server-and-routing When I run npm run build, the builds successfully, I get the following error:

TypeError: mobx_state_tree__WEBPACK_IMPORTED_MODULE_1__.types.identifier is not a function
    at Object.<anonymous> (/Users/abbasq6v/Documents/dev/react/antd/heroku-nextjs/.next/server/static/MPv274FiSI3tRFordioX_/pages/quotes.js:1215:61)
    at __webpack_require__ (/Users/abbasq6v/Documents/dev/react/antd/heroku-nextjs/.next/server/static/MPv274FiSI3tRFordioX_/pages/quotes.js:23:31)
    at Object.<anonymous> (/Users/abbasq6v/Documents/dev/react/antd/heroku-nextjs/.next/server/static/MPv274FiSI3tRFordioX_/pages/quotes.js:3114:18)
    at __webpack_require__ (/Users/abbasq6v/Documents/dev/react/antd/heroku-nextjs/.next/server/static/MPv274FiSI3tRFordioX_/pages/quotes.js:23:31)
    at Module.<anonymous> (/Users/abbasq6v/Documents/dev/react/antd/heroku-nextjs/.next/server/static/MPv274FiSI3tRFordioX_/pages/quotes.js:8729:19)
    at __webpack_require__ (/Users/abbasq6v/Documents/dev/react/antd/heroku-nextjs/.next/server/static/MPv274FiSI3tRFordioX_/pages/quotes.js:23:31)
    at Object.<anonymous> (/Users/abbasq6v/Documents/dev/react/antd/heroku-nextjs/.next/server/static/MPv274FiSI3tRFordioX_/pages/quotes.js:8691:18)
    at __webpack_require__ (/Users/abbasq6v/Documents/dev/react/antd/heroku-nextjs/.next/server/static/MPv274FiSI3tRFordioX_/pages/quotes.js:23:31)
    at /Users/abbasq6v/Documents/dev/react/antd/heroku-nextjs/.next/server/static/MPv274FiSI3tRFordioX_/pages/quotes.js:91:18
    at Object.<anonymous> (/Users/abbasq6v/Documents/dev/react/antd/heroku-nextjs/.next/server/static/MPv274FiSI3tRFordioX_/pages/quotes.js:94:10)

This is what my .babelrc looks like:

{
      "presets": [
          "@babel/preset-env",
          "next/babel"
      ],
      "plugins": [
          "@babel/plugin-transform-object-assign",
          ["@babel/plugin-proposal-decorators", { "legacy": true }],
          ["@babel/plugin-proposal-class-properties", { "loose": true }]
      ]
}

I tried installing and running in sandbox, but there are no issues there, which makes me wonder if I'm missing something in my babel config.

Any help would be appreciated

Most helpful comment

It works now. I had to change these few things to upgrade to MST 3:

  • t.identifier() to t.identifier
  • t.identifier(t.number) to t.identifierNumber
  • t.maybe() to t.maybeNull()

and it all started working. Thanks @xaviergonz

All 2 comments

use types.identifier as a constant rather than types.identifier() as a function.
it works because it changed in MST 3 and the sandbox uses v2 by default

It works now. I had to change these few things to upgrade to MST 3:

  • t.identifier() to t.identifier
  • t.identifier(t.number) to t.identifierNumber
  • t.maybe() to t.maybeNull()

and it all started working. Thanks @xaviergonz

Was this page helpful?
0 / 5 - 0 ratings