How to use several next.js plugins (typescript and stylus)
Asked Answered
O

2

3

I try to build next.js project with typescript and stylus using next-compose-plugins.

My next.config.js:

const withPlugins = require('next-compose-plugins')
const withTypescript = require('@zeit/next-typescript')
const withStylus = require('@zeit/next-stylus')

module.exports = withPlugins([

  [withTypescript, {
    webpack(config, options) {
      config.node = {
        fs: 'empty',
      }

      return config
    },
    typescriptLoaderOptions: {
      transpileOnly: false,
    }
  }],

  [withStylus, {
    cssModules: true,
  }],

])

In my button.tsx I'm importing stylus file:

import styles from './button.styl'
console.log(styles) // undefined

button.styl contains class names I'd like to use in my components but instead getting undefined.

I've added declare module '*.styl' to my externals.d.ts and included it in include section of tsconfig.json

What am I doing wrong?

UPD: getting same issue for @zeit/next-css.

Overseer answered 11/5, 2018 at 13:57 Comment(0)
M
2

@zeit/next-typescript 1.0.0 is released 3 days ago, and raise error with typescriptLoaderOptions:

Error: `typescriptLoaderOptions` in next.config.js is no longer supported. https://err.sh/next-plugins/typescript-loader-options
    at module.exports (/Users/set0gut1/tmp/stackoverflow/nextjs/node_modules/@zeit/next-typescript/index.js:15:11)

With this version, I could import stylus file.

  • next.config.js: delete typescriptLoaderOptions from yours.
  • I do not make externals.d.ts
  • index.tsx:

import styles from './button.styl'
console.log(styles) // { 'button-class-name': '_1U60cMSmedjISleJqYp7tU' }

export default () => {
    return <div>test</div>
}
Meister answered 15/5, 2018 at 17:28 Comment(0)
R
0

Consider using next-recompose-plugins to get clear information which plugin is causing the error.

Revenuer answered 26/3, 2023 at 16:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.