netlify 部署失败并出现错误 [vite]:汇总无法解析导入

问题描述 投票:0回答:2

部署到 netlify 失败并出现错误:

[vite]: Rollup failed to resolve import...
,但当我使用
npm run build
在本地构建时它可以工作(与 netlify 相同)。无法解析的包是直接从 github 安装的,而不是其他包。

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 日志:

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';

为什么在netlify部署失败,但在本地部署失败?

deployment svelte netlify rollup vite
2个回答
5
投票

LRUD 文档说

const { Lrud } = require('Lrud')

以下内容在本地有效:

import { Lrud } from 'Lrud';

这可能是因为 Mac 环境不关心此上下文中文件引用的大小写。然而,在 Netlify 上却有所不同。将导入语句更改为以下内容使 Netlify 部署通过:

import { Lrud } from 'lrud';

0
投票

我对这个错误有一个稍微不同的变体,在我的例子中,这是一个过度激励的 ts-autocomplete 添加随机(并且显然损坏)导入到某些文件(

import { scan } from "rxjs"
)。

如果上述修复不适用,我建议检查文件并查找可疑和未使用的导入。

© www.soinside.com 2019 - 2024. All rights reserved.