最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

reactjs - CRA Migration to Vite, Process to follow for issues with Rollup - Stack Overflow

programmeradmin4浏览0评论

In trying to migrate my codebase from CRA to Vite + TS, doing production builds is being very challenging with Rollup.

For example, the latest issue I'm facing is this error:

src/services/UIService.ts (14:9): "datadogRum" is not exported by "node_modules/@datadog/browser-rum/cjs/entries/main.js", imported by "src/services/UIService.ts".
file: src/services/UIService.ts:14:9

14: import { datadogRum } from "@datadog/browser-rum";

The package has an esm folder in it. It's package.json has:

  "main": "cjs/entries/main.js",
  "module": "esm/entries/main.js",
  "types": "cjs/entries/main.d.ts",

So I've gone into my vite.config.ts file and added, under alias:

{ find: '@datadog/browser-rum', replacement: path.resolve(__dirname, 'node_modules/@datadog/browser-rum/esm/entries/main.js') },
{ find: /^@datadog\/browser-rum($|\/.*)/, replacement: path.resolve(__dirname, 'node_modules/@datadog/browser-rum/esm/entries/main.js') },

and under optimizeDeps, and the exclude array, I've added '@datadog/browser-rum'.

I'm currently using the these 2 additional plugins:

import { nodePolyfills } from 'vite-plugin-node-polyfills';
import commonjs from 'vite-plugin-commonjs';

to fix other package issues for building.

This all works correctly when running Vite in dev and I confirmed the package has the right exports available.

I can get it to work however, by changing the import to this:

import { datadogRum } from "@datadog/browser-rum/esm/entries/main.js";

But I just get another error:

error during build:
node_modules/@datadog/browser-rum/esm/domain/deflate/deflateEncoder.js (1:9): "addEventListener" is not exported by "node_modules/@datadog/browser-core/cjs/index.js", imported by "node_modules/@datadog/browser-rum/esm/domain/deflate/deflateEncoder.js".
file: node_modules/@datadog/browser-rum/esm/domain/deflate/deflateEncoder.js:1:9

1: import { addEventListener, addTelemetryDebug, concatBuffers } from '@datadog/browser-core';
            ^
2: export function createDeflateEncoder(configuration, worker, streamId) {

However, I'd prefer to keep the original way. How do I fix this issue?

发布评论

评论列表(0)

  1. 暂无评论