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.

Antd-design-less example with export with Next > 7.0.2

See original GitHub issue

Bug report

Describe the bug

The bug happens when i export static NextJS app

> with-ant-design-less@1.0.0 export /Users/revskill/work/kms/kms-edu/src/with-ant-design-less
> next build && next export


✔ Client
  Compiled successfully in 28.09s

✔ Server
  Compiled successfully in 16.04s

> Using external babel configuration
> Location: "/Users/revskill/work/kms/kms-edu/src/with-ant-design-less/.babelrc"
 ┌ /
 ├ /_app
 ├ /_document
 └ /_error

> using build directory: /Users/revskill/work/kms/kms-edu/src/with-ant-design-less/.next
  copying "static build" directory
  launching 3 threads with concurrency of 10 per thread
/Users/revskill/work/kms/kms-edu/src/with-ant-design-less/node_modules/antd/lib/style/index.less:1
(function (exports, require, module, __filename, __dirname) { @import './themes/default';
                                                              ^

SyntaxError: Invalid or unexpected token
    at new Script (vm.js:84:7)
    at createScript (vm.js:264:10)
    at Object.runInThisContext (vm.js:312:10)
    at Module._compile (internal/modules/cjs/loader.js:696:28)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:747:10)
    at Module.load (internal/modules/cjs/loader.js:628:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:568:12)
    at Function.Module._load (internal/modules/cjs/loader.js:560:3)
    at Module.require (internal/modules/cjs/loader.js:665:17)
    at require (internal/modules/cjs/helpers.js:20:18)
{}

To Reproduce

Upgrading antd-less-design example with following dependencies:

{
  "name": "with-ant-design-less",
  "version": "1.0.0",
  "scripts": {
    "dev": "next",
    "build": "next build",
    "start": "next start",
    "export": "next build && next export"
  },
  "dependencies": {
    "@zeit/next-less": "^1.0.1",
    "antd": "3.12.4",
    "less": "^3.9.0",
    "next": "^8.0.0-canary.17",
    "react": "^16.7.0",
    "react-dom": "^16.7.0"
  },
  "license": "ISC",
  "devDependencies": {
    "babel-plugin-import": "^1.11.0"
  }
}

next.config.js:

/* eslint-disable */
const withLess = require('@zeit/next-less')


// fix: prevents error when .less files are required by node
if (typeof require !== 'undefined') {
  require.extensions['.less'] = file => {}
}

module.exports = withLess({
  lessLoaderOptions: {
    javascriptEnabled: true,
    modifyVars: {
      "@primary-color": '#1DA57A'
    }
  },
  exportPathMap: async function (defaultPathMap) {
    return {
      '/': { page: '/' },
    }
  }
})

Expected behavior

Exporting should be successfull.

Screenshots

screen shot 2019-01-31 at 7 27 43 am

System information

  • OS: MacOS
  • Browser : chrome
  • Version of Next.js: ^8.0.0-canary.17

Updated: The example worked with Next 7.0.2 , but not work with < 7.0.2 or 8.0.x

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:14
  • Comments:30 (8 by maintainers)

github_iconTop GitHub Comments

6reactions
teleginzhenyacommented, Jan 31, 2019

Hello! Did you see the example? Probably you need less-vars-to-js as it is in example.

Also try something like this

module.exports = withLess({
-  lessLoaderOptions: {
  javascriptEnabled: true,
  modifyVars: {
    "@primary-color": '#1DA57A'
+  },
-  },
  exportPathMap: async function (defaultPathMap) {
    return {
      '/': { page: '/' },
    }
  }
})
3reactions
thecodebosscommented, Feb 22, 2019

This require patch

// fix: prevents error when .less files are required by node
if (typeof require !== 'undefined') {
  require.extensions['.less'] = file => {}
}

gets executed on the main next export process, but then when it forks to spawn a bunch of workers, they don’t have this patch and so they fail once a .less file gets required.

I can’t think of a workaround to ensure that worker processes execute that patch code prior to running their main logic.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Antd-design-less example with export with Next > 7.0.2 #6181
I'm facing a similar issue with with-antd example cannot export but it runs okay with npm run dev . When I run next...
Read more >
Advanced Features: Static HTML Export | Next.js
Export your Next.js app to static HTML, and run it standalone without the need of a Node.js server.
Read more >
What is the difference between `next export` and `next build ...
I want to deploy this app to my server. I am using Nginx as the reverse proxy. The backend deployment is sorted. I...
Read more >
Static HTML Export with i18n compatibility in Next.js
Create a getStatic.js file and place it for example in a lib directory. import { serverSideTranslations } ...
Read more >
Export a Next.js Application with Nx - Egghead.io
When it comes to deploying Next.js based applications we have basically two different possibilities: "exporting" our app, or just building it.
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