next.js: “transform-decorators-legacy” does not work with next@7
“transform-decorators-legacy” works fine with next@6. Here is the version:
"dependencies": {
"mobx": "^5.1.2",
"mobx-react": "^5.2.8",
"next": "^6.1.2",
"babel-plugin-styled-components": "^1.7.1",
"babel-plugin-transform-decorators-legacy": "^1.3.5"
}
{
"presets": [
"next/babel"
],
"plugins": [
"transform-decorators-legacy",
[
"babel-plugin-styled-components",
{
"ssr": true,
"displayName": true,
"preprocess": false
}
]
]
}
Then change the version of next.js to 7.0.0. The error occurs:
Module build failed (from ./node_modules/next/dist/build/webpack/loaders/next-babel-loader.js): Error: The ‘decorators’ plugin requires a ‘decoratorsBeforeExport’ option, whose value must be a boolean. If you are migrating from Babylon/Babel 6 or want to use the old decorators proposal, you should use the ‘decorators-legacy’ plugin instead of ‘decorators’. at validatePlugins (C:\Users\Jim_K\Downloads\projects\hello-next\node_modules@babel\parser\lib\index.js:10421:13) at getParser (C:\Users\Jim_K\Downloads\projects\hello-next\node_modules@babel\parser\lib\index.js:10478:5) at parse (C:\Users\Jim_K\Downloads\projects\hello-next\node_modules@babel\parser\lib\index.js:10462:12) at parser (C:\Users\Jim_K\Downloads\projects\hello-next\node_modules@babel\core\lib\transformation\normalize-file.js:170:34) at normalizeFile (C:\Users\Jim_K\Downloads\projects\hello-next\node_modules@babel\core\lib\transformation\normalize-file.js:138:11) at runSync (C:\Users\Jim_K\Downloads\projects\hello-next\node_modules@babel\core\lib\transformation\index.js:44:43) at runAsync (C:\Users\Jim_K\Downloads\projects\hello-next\node_modules@babel\core\lib\transformation\index.js:35:14) at process.nextTick (C:\Users\Jim_K\Downloads\projects\hello-next\node_modules@babel\core\lib\transform.js:34:34) at process._tickCallback (internal/process/next_tick.js:61:11)
Is there any workaround for this? Or is there another decorator plugin which can work with next@7?
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 9
- Comments: 20 (2 by maintainers)
I use
["@babel/plugin-proposal-decorators", { "legacy": true }]and this works for meIt is extremely tricky to use mobx together with next@7. After spending several days investigating next@7, mobx, bable plugins, I make the minimal sample code of “mobx + next@7”. Here is the repo: “https://github.com/jim-king-2000/nextbugrepro.git” “git@github.com:jim-king-2000/nextbugrepro.git”
The trickiest thing is in the .babelrc file.
We have to use the two plugins above for the decorator grammar. And the order of the two plugins cannot be reversed.
I strongly suggest that “mobx + next@7” should be added into the tutorial of next.js.
I just upgrade to next@7 and also use this config:
But still see the error:
Support for the experimental syntax 'decorators-legacy' isn't currently enabled (9:1):at@withI18next('translations')This is my package.json
And the next.config.js
Please correct me. Thanks.
@MaxGraey @cdonohue ,
["@babel/plugin-proposal-decorators", { "legacy": true }]works with next@7, but not with next@6. And,transform-decorators-legacyworks with next@6 while not with next@7. My problem has been resolved, I’ll use["@babel/plugin-proposal-decorators", { "legacy": true }]together with next@7. However, the situation of mobx + next@6 or next@7 is still messy.It works! Thank @MaxGraey . I’ll use
["@babel/plugin-proposal-decorators", { "legacy": true }]instead.@jim-king-2000 did you try adding the
decoratorsBeforeExportoption to your Babel configuration?Hi Looks like it a Babel related, not a Next (sorry, if I’m not right). Do you read Babel doc about transform-decorators?
See “https://github.com/jim-king-2000/mobxSampleWithNext7” for mobx + next@7.