question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

nextjs 6.0.1 with-typescript babel problem

See original GitHub issue

I have updated to NextJS 6.0.1 I corrected babel errors with babel-upgrade but there is a problem I can not solve

ModuleBuildError: Module build failed: SyntaxError: ...\pages\index.tsx: Unexpected token (9:9)
   7 |
   8 | class IndexPage extends Component {
>  9 |   public static async getInitialProps(context, apolloClient) {
     |          ^
  10 |     await initial(context, apolloClient);
  11 |     await seo(context, {
  12 |       title: {
    at _class.raise (...\node_modules\next\node_modules\babylon\lib\index.js:778:15)
    at _class.unexpected (...\node_modules\next\node_modules\babylon\lib\index.js:2063:16)
    at _class.parseClassMemberWithIsStatic (...\node_modules\next\node_modules\babylon\lib\index.js:4815:12)
    at _class.parseClassMember (...\node_modules\next\node_modules\babylon\lib\index.js:4708:10)
    at _class.parseClassBody (...\node_modules\next\node_modules\babylon\lib\index.js:4663:12)
    at _class.parseClass (...\node_modules\next\node_modules\babylon\lib\index.js:4613:10)
    at _class.parseStatementContent (...\node_modules\next\node_modules\babylon\lib\index.js:3954:21)
    at _class.parseStatement (...\node_modules\next\node_modules\babylon\lib\index.js:3926:17)
    at _class.parseBlockOrModuleBlockBody (...\node_modules\next\node_modules\babylon\lib\index.js:4470:23)
    at _class.parseBlockBody (...\node_modules\next\node_modules\babylon\lib\index.js:4457:10)
    at _class.parseTopLevel (...\node_modules\next\node_modules\babylon\lib\index.js:3902:10)
    at _class.parse (...\node_modules\next\node_modules\babylon\lib\index.js:5250:17)
    at parse (...\node_modules\next\node_modules\babylon\lib\index.js:9972:38)
    at parser (...\node_modules\next\node_modules\@babel\core\lib\transformation\normalize-file.js:106:33)
    at normalizeFile (...\node_modules\next\node_modules\@babel\core\lib\transformation\normalize-file.js:53:11)
    at runSync (...\node_modules\next\node_modules\@babel\core\lib\transformation\index.js:34:41)
    at runAsync (...\node_modules\next\node_modules\@babel\core\lib\transformation\index.js:25:14)
    at ...\node_modules\next\node_modules\@babel\core\lib\transform.js:32:34
    at process._tickCallback (internal/process/next_tick.js:112:11)
    at runLoaders (...\node_modules\webpack\lib\NormalModule.js:195:19)
    at ...\node_modules\loader-runner\lib\LoaderRunner.js:364:11
    at ...\node_modules\loader-runner\lib\LoaderRunner.js:230:18
    at context.callback (...\node_modules\loader-runner\lib\LoaderRunner.js:111:13)
    at ...\node_modules\next\node_modules\babel-loader\lib\index.js:98:23
    at ...\node_modules\next\node_modules\babel-loader\lib\cache.js:120:25
    at ...\node_modules\next\node_modules\babel-loader\lib\transform.js:8:72
    at runAsync (...\node_modules\next\node_modules\@babel\core\lib\transformation\index.js:27:12)
    at ...\node_modules\next\node_modules\@babel\core\lib\transform.js:32:34
    at process._tickCallback (internal/process/next_tick.js:112:11)

If index.tsx is just that, it’s not a problem

export default ()=><div>Example</div>;

.babelrc

{
    "env": {
        "development": {
            "plugins": [
                
            ]
        },
        "production": {
            "plugins": [
                [
                    "react-intl",
                    {
                        "messagesDir": "language/.messages/"
                    }
                ]
            ]
        }
    },
    "presets": [
        "@babel/preset-env",
        "@babel/preset-react", [
            "@babel/preset-stage-0",
            {
                "decoratorsLegacy": true
            }
        ], ["next/babel", {
            "preset-env": {
                "targets": {
                    "browsers": "> 5%"
                }
            }
        }]
    ],
    "plugins": [
        [
            "transform-imports",
            {
                "material-ui": {
                    "transform": "material-ui/${member}",
                    "preventFullImport": true
                }
            }
        ]
    ]
}

next.config.js

const withPlugins = require('next-compose-plugins');

const withTypescript = require('@zeit/next-typescript');

const withSass = require('@zeit/next-sass');

const withBundleAnalyzer = require('@zeit/next-bundle-analyzer');
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');

const withImages = require('next-images');

const withGraphql = require('next-plugin-graphql');

const withProgressBar = require('next-progressbar');

const withSourceMaps = require('@zeit/next-source-maps');

let plugins = [
  [withTypescript],
  [withSass],
  [withImages],
  [withGraphql],
  [withProgressBar],
  [
    withBundleAnalyzer,
    {
      analyzeServer: ['server', 'both'].includes(process.env.BUNDLE_ANALYZE),
      analyzeBrowser: ['browser', 'both'].includes(process.env.BUNDLE_ANALYZE),
      bundleAnalyzerConfig: {
        server: {
          analyzerMode: 'static',
          reportFilename: '../../bundles/server.html'
        },
        browser: {
          analyzerMode: 'static',
          reportFilename: '../bundles/client.html'
        }
      }
    }
  ],
  [
    (nextConfig = {}) =>
      Object.assign({}, nextConfig, {
        webpack(config, options) {
          const path = require('path');
          if (!options.defaultLoaders) {
            throw new Error(
              'This plugin is not compatible with Next.js versions below 5.0.0 https://err.sh/next-plugins/upgrade'
            );
          }

          const { dir, defaultLoaders, dev, isServer } = options;

          const originalEntry = config.entry;
          config.entry = async () => {
            const entries = await originalEntry();

            if (entries['main.js']) {
              entries['main.js'].unshift('./utils/client/polyfills.ts');
            }

            return entries;
          };

          if (typeof nextConfig.webpack === 'function') {
            return nextConfig.webpack(config, options);
          }

          return config;
        }
      })
  ]
];

if (process.env.NODE_ENV !== 'production') {
  plugins = plugins.concat([withSourceMaps]);
}

module.exports = withPlugins(plugins);

package.json

{
  "dependencies": {
    "@babel/core": "7.0.0-beta.44",
    "@babel/preset-env": "7.0.0-beta.44",
    "@babel/preset-react": "^7.0.0-beta.44",
    "@babel/preset-stage-0": "7.0.0-beta.44",
    "@babel/register": "7.0.0-beta.44",
    "@zeit/next-bundle-analyzer": "^0.1.1",
    "@zeit/next-sass": "^0.2.0",
    "@zeit/next-source-maps": "^0.0.2",
    "@zeit/next-typescript": "1.0.0",
    "animate.css": "^3.6.1",
    "apollo-cache-inmemory": "^1.2.1",
    "apollo-client": "^2.3.1",
    "apollo-link": "^1.2.2",
    "apollo-link-context": "^1.0.8",
    "apollo-link-ws": "^1.0.8",
    "apollo-server-express": "^1.3.6",
    "apollo-upload-client": "^8.0.0",
    "apollo-upload-server": "^5.0.0",
    "apollo-utilities": "^1.0.12",
    "babel-plugin-react-intl": "^2.4.0",
    "babel-plugin-transform-define": "^1.3.0",
    "babel-plugin-transform-imports": "^1.5.0",
    "cachegoose": "^7.0.0",
    "cookie-parser": "^1.4.3",
    "cors": "^2.8.4",
    "csurf": "^1.9.0",
    "dotenv": "^5.0.1",
    "es6-promise": "^4.2.4",
    "express": "^4.16.3",
    "figlet": "^1.2.0",
    "graphql": "^0.13.2",
    "graphql-depth-limit": "^1.1.0",
    "graphql-redis-subscriptions": "^1.5.0",
    "graphql-scalar-objectid": "^0.1.0",
    "graphql-type-json": "^0.2.1",
    "helmet": "^3.12.0",
    "humanize-plus": "^1.8.2",
    "intl": "^1.2.5",
    "intl-locales-supported": "^1.0.0",
    "ioredis": "^3.2.2",
    "isomorphic-unfetch": "^2.0.0",
    "js-cookie": "^2.2.0",
    "jsonwebtoken": "^8.2.1",
    "material-ui": "^1.0.0-beta.43",
    "material-ui-pickers": "^1.0.0-rc.7",
    "mongoose": "^5.1.0",
    "morgan": "^1.9.0",
    "next": "^6.0.1",
    "next-compose-plugins": "^2.1.1",
    "next-images": "^0.10.2",
    "next-plugin-graphql": "^0.0.1",
    "next-progressbar": "^0.0.2",
    "next-redux-saga": "^3.0.0-beta.1",
    "next-redux-wrapper": "^2.0.0-beta.6",
    "next-routes": "^1.4.1",
    "node-sass": "^4.9.0",
    "normalize.css": "^8.0.0",
    "nprogress": "^0.2.0",
    "postcss-cssnext": "^3.1.0",
    "postcss-easy-import": "^3.0.0",
    "pretty-ms": "^3.1.0",
    "promises-all": "^1.0.0",
    "raven": "^2.6.1",
    "react": "^16.3.2",
    "react-apollo": "^2.1.4",
    "react-dom": "^16.3.2",
    "react-ga": "^2.5.0",
    "react-helmet": "^5.2.0",
    "react-intl": "^2.4.0",
    "react-jss": "^8.4.0",
    "react-redux": "^5.0.7",
    "redux": "^4.0.0",
    "redux-devtools-extension": "^2.13.2",
    "redux-logger": "^3.0.6",
    "redux-saga": "^0.16.0",
    "replace-in-file": "^3.4.0",
    "request-ip": "^2.0.2",
    "rotating-file-stream": "^1.3.6",
    "subscriptions-transport-ws": "^0.9.9",
    "unhandled-rejection": "^1.0.0",
    "url-parse": "^1.4.0",
    "validator": "^10.2.0",
    "xss": "^0.3.8"
  },
  "devDependencies": {
    "@types/core-js": "^0.9.46",
    "@types/dotenv": "^4.0.3",
    "@types/express": "^4.11.1",
    "@types/jest": "^22.2.3",
    "@types/next": "^2.4.10",
    "@types/react": "^16.3.14",
    "@types/react-dom": "^16.0.5",
    "babel-core": "^7.0.0-bridge.0",
    "enzyme": "^3.3.0",
    "enzyme-adapter-react-16": "^1.1.1",
    "jest": "^22.4.3",
    "nodemon": "^1.17.4",
    "react-addons-test-utils": "^15.6.2",
    "react-test-renderer": "^16.3.2",
    "ts-jest": "^22.4.6",
    "ts-node": "^6.0.3"
  }
}

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
mtford90commented, Jul 5, 2018

@omeraplak i ditched module and namespace entirely. Not ideal but can cope without them.

1reaction
mtford90commented, May 23, 2018

Ahhhh thanks @timneutkens - my bad.

I’m getting a new error now:

Module build failed: SyntaxError: /Users/mtford/Playground/punterslounge.com/lib/components/Layout.tsx: Namespaces are not supported.

Is this something to do with babel typescript support? Can’t seem to find anything about this issue online. I can of course rewrite without namespaces but a tad annoying.

Read more comments on GitHub >

github_iconTop Results From Across the Web

nextjs 6.0.1 with-typescript babel problem · Issue #4354 - GitHub
I have updated to NextJS 6.0.1 I corrected babel errors with babel-upgrade but there is a problem I can not solve ModuleBuildError: Module ......
Read more >
Advanced Features: Customizing Babel Config - Next.js
To start, you only need to define a .babelrc file (or babel.config.js ) at the top of your app. If such a file...
Read more >
webpack - Failed to build and deploy Next.js app to vercel ...
I found the issue. It was in one of my Next App pages. I had to remove unused modules.
Read more >
eslint: failed to load config "next/babel" to extend from. - You.com
I'm facing this problem deploying my site on vercel from my github repo repo link: https://github.com/hammadsohail/ecommerce_sanity_stripe here is my ...
Read more >
If TypeScript is so great, how come all notable ReactJS ...
I agree though over-fragmentation is a huge problem for JS, ... Babel has faltered since the V6 release, TypeScript is still growing fast, ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found