Using markdownit module, each plugin is replaced with null

chrisvfritz
21
chrisvfritz
commented 3 years ago

With this config:

modules: [
  '@nuxtjs/pwa',
  [
    '@nuxtjs/markdownit', {
      preset: 'default',
      linkify: true,
      breaks: true,
      preprocess: function (markdownIt, source) {
        // do any thing
        return source
      },
      use: [
        require('markdown-it-container'),
        require('markdown-it-attrs')
      ]
    }
  ]
]

I'm getting the error:

Module build failed: TypeError: Cannot read property 'apply' of null
    at MarkdownIt.use (/...project.../node_modules/markdown-it/lib/index.js:496:9)
    at /...project.../node_modules/markdownit-loader/lib/core.js:66:18
    at Array.forEach (native)
    at Object.module.exports (/...project.../node_modules/markdownit-loader/lib/core.js:62:15)

The problem is that sometime before these options are passed to the module, each item in the use array has been replaced by null, resulting in [null, null]. MarkdownIt doesn't like null plugins, so we get the error.

bug
1
pi0
39.6k
pi0
commented 3 years ago

Hey @chrisvfritz . Thanks for spotting this bug, actually it seems root problem backs to how vue-loader works, which magically makes opts.use[] children to null! Also it works fine with import '~/docs/foobar.md')
So as a quick workaround i'm going to add lazy require support for markdown-it loader. Will keep this thread updated.

0
pi0
39.6k
pi0
commented 3 years ago

The problem should now resolve with the latest release. I've also updated readme.

0
chrisvfritz
21
chrisvfritz
commented 3 years ago

Woohoo! Thanks. ๐Ÿ™‚

0
phikhi
5
phikhi
commented 2 years ago

@pi0 @chrisvfritz I have the same error while trying to load markdown-it-attrs plugin.

Error message : Module build failed: TypeError: Cannot read property 'apply' of null

Here is my nuxt.config.js

markdownit: {
    preset: 'default',
    linkify: true,
    breaks: true,
    use: [
      require('markdown-it-attrs')
    ]
  },

I'm using these packages

[email protected]1.4.0
@nuxtjs/[email protected]1.2.0
markdown-it-[email protected]1.2.1

Is there anything that I am missing here ?

0
Informations
Bug Report โ€ข Open
#c42 - Created 3 years ago