bennypowers / rollup-plugin-modulepreload

Rollup plugin to add modulepreload links from generated chunks.
MIT License
16 stars 0 forks source link

Default build settings not working for me. Giving various undefined issues. #6

Closed SamuelFrost closed 3 years ago

SamuelFrost commented 3 years ago

I imagine I'm just not setting it up right, but starting simply first, I'm getting some undefined messages when I try to build with any of the standard setups in the readme. (in plugins)

modulepreload({
  index: 'index.html',
  shouldPreload: ({ facadeModuleId }) =>
    fs.promises.readFile(facadeModuleId, 'utf-8')
      .then(file => file.includes('INCLUDE THIS CHUNK')),
})

result:

[!] (plugin modulepreload) ReferenceError: fs is not defined
ReferenceError: fs is not defined
    at shouldPreload (.../rollup.config.js:85:12)

(in plugins)

modulepreload({
  index: 'index.html',
})

result:

[!] (plugin modulepreload) TypeError: Cannot read property 'length' of undefined
TypeError: Cannot read property 'length' of undefined
    at defaultShouldPreload (.../node_modules/rollup-plugin-modulepreload/index.js:23:33)

After adding: import fs from 'fs'; at the top of rollup config

Getting this:

[!] (plugin modulepreload) TypeError: The "path" argument must be of type string or an instance of Buffer or URL. Received null
TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string or an instance of Buffer or URL. Received null
    at open (internal/fs/promises.js:306:10)

Here's my project for reference. I've created the modulepreload branch for tackling this problem and pushed code producing the build error. https://github.com/SamuelFrost/portfolio/tree/modulepreload/portfolio-application

bennypowers commented 3 years ago

Try with v1.2.3. If you customize shouldPreload, please consult the updated README

Please reopen if this doesn't fix.