ionic-team / ionic-team/rollup-plugin-node-polyfills
Type Error Importer
- 主要语言
- JavaScript
- 星标
- 142
- 派生
- 65
- PR 合并指标
- 30 天内没有已合并 PR
描述
When I try to use `nodePolyfills({ crypto: true })` as rollup option, i get following type error:
```
Type '{ name: string; resolveId(importee: string, importer: string): { id: any; moduleSideEffects: boolean; } | null; load(id: string): string | undefined; transform(code: string, id: string): any; }' is not assignable to type 'InputPluginOption'.
Type '{ name: string; resolveId(importee: string, importer: string): { id: any; moduleSideEffects: boolean; } | null; load(id: string): string | undefined; transform(code: string, id: string): any; }' is not assignable to type 'Plugin'.
Types of property 'resolveId' are incompatible.
Type '(importee: string, importer: string) => { id: any; moduleSideEffects: boolean; } | null' is not assignable to type 'ObjectHook<(this: PluginContext, source: string, importer: string | undefined, options: { assertions: Record; custom?: CustomPluginOptions | undefined; isEntry: boolean; }) => ResolveIdResult | Promise<...>, {}> | undefined'.
Type '(importee: string, importer: string) => { id: any; moduleSideEffects: boolean; } | null' is not assignable to type '(this: PluginContext, source: string, importer: string | undefined, options: { assertions: Record; custom?: CustomPluginOptions | undefined; isEntry: boolean; }) => ResolveIdResult | Promise<...>'.
Types of parameters 'importer' and 'importer' are incompatible.
Type 'string | undefined' is not assignable to type 'string'.
Type 'undefined' is not assignable to type 'string'.
28 plugins: [nodePolyfills()],
~~~~~~~~~~~~~~~
```
This is my `vite.config.ts`:
```
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import { NodeGlobalsPolyfillPlugin } from '@esbuild-plugins/node-globals-polyfill';
import nodePolyfills from 'rollup-plugin-node-polyfills';
// https://vitejs.dev/config/
export default defineConfig({
server: {
port: 3000,
},
plugins: [react()],
resolve: {
alias: {
stream: 'rollup-plugin-node-polyfills/polyfills/stream',
events: 'rollup-plugin-node-polyfills/polyfills/events',
assert: 'assert',
crypto: 'crypto-browserify',
util: 'util',
'near-api-js': 'near-api-js/dist/near-api-js.js',
},
},
define: {
'process.env': process.env ?? {},
},
build: {
target: 'esnext',
rollupOptions: {
plugins: [nodePolyfills({ crypto: true })],
},
},
optimizeDeps: {
esbuildOptions: {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
plugins: [NodeGlobalsPolyfillPlugin({ buffer: true }) as any],
},
},
});
```
Replicated the issue here: https://stackblitz.com/edit/vitejs-vite-uqkmtp?file=vite.config.ts
Does anybody have an idea how to solve this?
贡献指南
这个仓库没有索引到贡献指南
调研方向
Start with the vite.config.ts example and the StackBlitz reproduction, focusing on nodePolyfills({ crypto: true }) in build.rollupOptions.plugins. Reproduce the TypeScript incompatibility and inspect the plugin's Rollup hook types. Done means the configuration type-checks without the reported resolveId error while retaining the crypto option.
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- rollup, typescript, vite
- 领域
- build-system
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100