DEV Community

isaack okello brian
isaack okello brian

Posted on

Need help with next.config.js

Alt Text

How can i write this without having it throw an error?

const withSass = require("@zeit/next-sass");
const withLess = require("@zeit/next-less");
const withCSS = require("@zeit/next-css");
const path = require("path");

const isProd = process.env.NODE_ENV === "production";

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

module.exports = webpack: (config) => {
config.resolve.alias['components'] = path.join(dirname,'components')
config.resolve.alias['public'] = path.join(
dirname,'public')
return config;
},withCSS({
cssModules: true,
cssLoaderOptions: {
importLoaders: 1,
localIdentName: "[local]___[hash:base64:5]",
},
...withLess(
withSass({
lessLoaderOptions: {
javascriptEnabled: true,
},
})
),
});

Top comments (13)

Collapse
 
alejandronanez profile image
Alejandro Ñáñez Ortiz •

This is a bit difficult to read, I'd suggest using

``` so the code looks a bit better.

Still, I think that your problem is that you have



module.exports = webpack: (config) => {


And it should be



module.exports = (config) => {


Collapse
 
kulgeek profile image
isaack okello brian •

I still get an error but I uploaded a cover photo

Collapse
 
kulgeek profile image
isaack okello brian •

And the rest should remain as is? Sorry im super new to this, can you rewrite the whole of it. Teach me sensei

Collapse
 
kulgeek profile image
isaack okello brian •

Heres the polacode

Collapse
 
alejandronanez profile image
Alejandro Ñáñez Ortiz •

No worries, everyone has been new to something in their life.

I should try with what I suggested and paste the error again, remember to wrap your code within


Thread Thread
 
kulgeek profile image
isaack okello brian •

Okay let me try that

Thread Thread
 
kulgeek profile image
isaack okello brian •
Thread Thread
 
kulgeek profile image
isaack okello brian •

Theres the error - can you see the screenshots?

Thread Thread
 
alejandronanez profile image
Alejandro Ñáñez Ortiz •

What error are you getting? 🤔

Do you have it on a repo/gist or something?

Thread Thread
 
kulgeek profile image
isaack okello brian •

@alejandro Ñanez Ortiz here is a github link github.com/kulgeek/rds-app/blob/ma...

 
kulgeek profile image
isaack okello brian •
Collapse
 
kulgeek profile image
isaack okello brian •

ERROR:

yarn run v1.22.4
warning ../package.json: No license field
$ next dev
/Users/isaackbrian/Documents/WORKSPACE/Dev/rds-app/next.config.js:13
module.exports = webpack: (config) => {
^

SyntaxError: Unexpected token ':'
at wrapSafe (internal/modules/cjs/loader.js:1172:16)
at Module._compile (internal/modules/cjs/loader.js:1220:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1277:10)
at Module.load (internal/modules/cjs/loader.js:1105:32)
at Function.Module._load (internal/modules/cjs/loader.js:967:14)
at Module.require (internal/modules/cjs/loader.js:1145:19)
at require (internal/modules/cjs/helpers.js:75:18)
at loadConfig (/Users/isaackbrian/Documents/WORKSPACE/Dev/rds-app/node_modules/next/dist/next-server/server/config.js:6:116)
at new Server (/Users/isaackbrian/Documents/WORKSPACE/Dev/rds-app/node_modules/next/dist/next-server/server/next-server.js:1:3860)
at new DevServer (/Users/isaackbrian/Documents/WORKSPACE/Dev/rds-app/node_modules/next/dist/server/next-dev-server.js:1:2964)
error Command failed with exit code 1.
info Visit yarnpkg.com/en/docs/cli/run for documentation about this command.

Collapse
 
kulgeek profile image
isaack okello brian •