[vite]: Rollup failed to resolve import "laravel-nova"

Oct 5, 2022 by Jose Garrido

Today I found myself with the following error from Vite:

[vite]: Rollup failed to resolve import "laravel-nova" from "resources/js/components/FroalaEditor/FormField.vue".
This is most likely unintended because it can break your application at runtime.
If you do want to externalize this module explicitly add it to
`build.rollupOptions.external`
error during build:
[vite]: Rollup failed to resolve import "froala-editor" from "resources/js/components/FroalaEditor/FormField.vue".
This is most likely unintended because it can break your application at runtime.
If you do want to externalize this module explicitly add it to
`build.rollupOptions.external`
error during build:

This happened when trying to compile a custom Plugin I'm building with Laravel Nova 4 for Froala.

After Googling, to my surprise, nothing was found so rolling up my sleeves and after some testing I found that I just needed to include those two libraries as external dependencies in my vite.config.js file under the rollup section.

export default defineConfig({
    plugins: [vue()],
    build: {
        lib: {
          entry: resolve('./resources/js/field.js'),
          name: 'FroalaField',
          fileName: 'froala-field'
        },
        rollupOptions: {
          external: ['vue', 'laravel-nova', 'froala-editor'],
          output: {
            globals: {
              vue: 'Vue'
            }
          }
        }
    }
});

This solved the problem and I was able to compile my plugin without more problems.

Did you like the article? Consider subscribing to the newsletter.

The latest articles and resources, sent directly to your inbox. The best part? It's free.