'netlify deploy fails with error [vite]: Rollup failed to resolve import
Deploying to netlify fails with error: [vite]: Rollup failed to resolve import..., but it works when I build locally using npm run build (same as netlify). The package that fails to resolve is installed directly from github, as opposed to the other packages.
package.json:
"dependencies": {
"@tailwindcss/line-clamp": "^0.2.2",
"focus-visible": "^5.2.0",
"just-throttle": "^4.0.1",
"lrud": "github:bbc/lrud#master",
"sapper-environment": "^1.0.1"
}
netlify logs:
10:10:48 PM: ────────────────────────────────────────────────────────────────
10:10:48 PM: 1. build.command from netlify.toml
10:10:48 PM: ────────────────────────────────────────────────────────────────
10:10:48 PM:
10:10:48 PM: $ npm run build
10:10:48 PM: > [email protected] build
10:10:48 PM: > svelte-kit build
10:10:49 PM: vite v2.7.10 building for production...
10:10:49 PM: transforming...
10:10:52 PM: ✓ 54 modules transformed.
10:10:52 PM: [vite]: Rollup failed to resolve import "Lrud" from "src/lib/stores/keyNavigation.ts".
10:10:52 PM: This is most likely unintended because it can break your application at runtime.
10:10:52 PM: If you do want to externalize this module explicitly add it to
10:10:52 PM: `build.rollupOptions.external`
keyNavigation.ts:
import { Lrud } from 'Lrud';
Why does deployment fail at netlify, but not locally?
Solution 1:[1]
The LRUD documentation says
const { Lrud } = require('Lrud')
and the following works locally:
import { Lrud } from 'Lrud';
That is probably because the Mac environment doesn't care about upper/lower case in file references in this context. However, on Netlify it makes a difference. Changing the import statement to the following made the Netlify deployment pass:
import { Lrud } from 'lrud';
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Per Quested Aronsson |
