When I use vite5 for building I get the warning #3219

Closed
opened 2024-09-14 07:11:56 +00:00 by lvzhenbo · 7 comments
packages/xlsx/xlsx.mjs (4007:27): A comment

"/*#__PURE__*/"

in "packages/xlsx/xlsx.mjs" contains an annotation that Rollup cannot interpret due to the position of the comment. The comment will be removed to avoid issues.

I think this issue is related to the rollup4 change
https://github.com/rollup/rollup/releases/tag/v4.0.0
https://github.com/rollup/rollup/pull/5165

``` packages/xlsx/xlsx.mjs (4007:27): A comment "/*#__PURE__*/" in "packages/xlsx/xlsx.mjs" contains an annotation that Rollup cannot interpret due to the position of the comment. The comment will be removed to avoid issues. ``` I think this issue is related to the rollup4 change https://github.com/rollup/rollup/releases/tag/v4.0.0 https://github.com/rollup/rollup/pull/5165
Owner

The offending line is:

var utf8read = has_buf && (/*#__PURE__*/utf8readc(utf8corpus) == /*#__PURE__*/utf8reada(utf8corpus) && utf8readc || /*#__PURE__*/utf8readb(utf8corpus) == /*#__PURE__*/utf8reada(utf8corpus) && utf8readb) || utf8reada;

Can you confirm whether the following replacement elicits the same warning:

var utf8read = /*#__PURE__*/(function() {
  if(has_buf) {
    if(utf8readc(utf8corpus) == utf8reada(utf8corpus)) return utf8readc;
    if(utf8readb(utf8corpus) == utf8reada(utf8corpus)) return utf8readb;
  }
  return utf8reada;
})();

We've had to do this transform in a few places before.

The offending line is: ```js var utf8read = has_buf && (/*#__PURE__*/utf8readc(utf8corpus) == /*#__PURE__*/utf8reada(utf8corpus) && utf8readc || /*#__PURE__*/utf8readb(utf8corpus) == /*#__PURE__*/utf8reada(utf8corpus) && utf8readb) || utf8reada; ``` Can you confirm whether the following replacement elicits the same warning: ```js var utf8read = /*#__PURE__*/(function() { if(has_buf) { if(utf8readc(utf8corpus) == utf8reada(utf8corpus)) return utf8readc; if(utf8readb(utf8corpus) == utf8reada(utf8corpus)) return utf8readb; } return utf8reada; })(); ``` We've had to do this transform in a few places before.
Author

Yes, if we make this change, there won't be any problem

Yes, if we make this change, there won't be any problem
Owner

Before committing the change, how can we reproduce the error?

Following the ViteJS Bundler demo, using vite v5.4.6, neither npm run dev nor npx vite build show that error when using the original form.

Before committing the change, how can we reproduce the error? Following the [ViteJS Bundler demo](https://docs.sheetjs.com/docs/demos/frontend/bundler/vitejs#complete-example), using vite v5.4.6, neither `npm run dev` nor `npx vite build` show that error when using the original form.
Author

I am currently unable to reproduce it simply because the environment I am using is quite complex. I can only provide the code for using xlsx

import { utils, writeFile } from 'xlsx';
if (model.value.wjlxbm == 'excel2003') {
          const workSheet = utils.aoa_to_sheet([
            selectedHeaderOptions.map((header) => header.label),
            ...newData,
          ]);
          // 设置列宽
          workSheet['!cols'] = columnWidths.map((width) => ({ wch: width }));
          const workBook = utils.book_new();
          utils.book_append_sheet(workBook, workSheet, 'Sheet1');
          writeFile(workBook, fileName + '.xlsx', { bookType: 'xls' });
        } else if (model.value.wjlxbm == 'excel2007') {
          const workSheet = utils.aoa_to_sheet([
            selectedHeaderOptions.map((header) => header.label),
            ...newData,
          ]);
          // 设置列宽
          workSheet['!cols'] = columnWidths.map((width) => ({ wch: width }));
          const workBook = utils.book_new();
          utils.book_append_sheet(workBook, workSheet, 'Sheet1');
          writeFile(workBook, fileName + '.xlsx');
        } else if (model.value.wjlxbm == 'csv') {
          // CSV using xlsx library
          const csvWorkbook = utils.book_new();
          const csvSheet = utils.aoa_to_sheet([
            selectedHeaderOptions.map((header) => header.label),
            ...newData,
          ]);
          // 设置列宽
          csvSheet['!cols'] = columnWidths.map((width) => ({ wch: width }));
          utils.book_append_sheet(csvWorkbook, csvSheet, 'Sheet1');
          writeFile(csvWorkbook, fileName + '.csv', {
            bookType: 'csv',
            type: 'binary',
          });
        }
I am currently unable to reproduce it simply because the environment I am using is quite complex. I can only provide the code for using xlsx ```ts import { utils, writeFile } from 'xlsx'; if (model.value.wjlxbm == 'excel2003') { const workSheet = utils.aoa_to_sheet([ selectedHeaderOptions.map((header) => header.label), ...newData, ]); // 设置列宽 workSheet['!cols'] = columnWidths.map((width) => ({ wch: width })); const workBook = utils.book_new(); utils.book_append_sheet(workBook, workSheet, 'Sheet1'); writeFile(workBook, fileName + '.xlsx', { bookType: 'xls' }); } else if (model.value.wjlxbm == 'excel2007') { const workSheet = utils.aoa_to_sheet([ selectedHeaderOptions.map((header) => header.label), ...newData, ]); // 设置列宽 workSheet['!cols'] = columnWidths.map((width) => ({ wch: width })); const workBook = utils.book_new(); utils.book_append_sheet(workBook, workSheet, 'Sheet1'); writeFile(workBook, fileName + '.xlsx'); } else if (model.value.wjlxbm == 'csv') { // CSV using xlsx library const csvWorkbook = utils.book_new(); const csvSheet = utils.aoa_to_sheet([ selectedHeaderOptions.map((header) => header.label), ...newData, ]); // 设置列宽 csvSheet['!cols'] = columnWidths.map((width) => ({ wch: width })); utils.book_append_sheet(csvWorkbook, csvSheet, 'Sheet1'); writeFile(csvWorkbook, fileName + '.csv', { bookType: 'csv', type: 'binary', }); } ```
Owner

The environment is the only relevant part. Can you share the following:

  • ViteJS version. You can run the following in WSL or Bash:
grep version node_modules/vite/package.json
  • RollupJS version:
grep version node_modules/rollup/package.json
  • Vite config. It will either be vite.config.js or vite.config.ts at the root of your project

  • Any RollupJS config files (if they exist). According to the ViteJS docs, RollupJS options should be specified in the ViteJS config under build.rollupOptions, but you may have an unconventional setup

The environment is the only relevant part. Can you share the following: - ViteJS version. You can run the following in WSL or Bash: ```bash grep version node_modules/vite/package.json ``` - RollupJS version: ```bash grep version node_modules/rollup/package.json ``` - Vite config. It will either be `vite.config.js` or `vite.config.ts` at the root of your project - Any RollupJS config files (if they exist). According to the [ViteJS docs](https://vitejs.dev/config/build-options#build-rollupoptions), RollupJS options should be specified in the ViteJS config under `build.rollupOptions`, but you may have an unconventional setup
Author

vite: 5.4.6
rollup: 4.21.1

build: {
      // https://cn.vitejs.dev/guide/build.html#browser-compatibility
      target: 'es2015',
      outDir: 'dist/' + VITE_PUBLIC_PATH,
      sourcemap: false,
      // 消除打包大小超过500kb警告
      chunkSizeWarningLimit: 4000,
      rollupOptions: {
        input: {
          index: pathResolve('./index.html', import.meta.url),
        },
        // 静态资源分类打包
        output: {
          chunkFileNames: 'static/js/[name]-[hash].js',
          entryFileNames: 'static/js/[name]-[hash].js',
          assetFileNames: 'static/[ext]/[name]-[hash].[ext]',
        },
      },
    },
vite: 5.4.6 rollup: 4.21.1 ```ts build: { // https://cn.vitejs.dev/guide/build.html#browser-compatibility target: 'es2015', outDir: 'dist/' + VITE_PUBLIC_PATH, sourcemap: false, // 消除打包大小超过500kb警告 chunkSizeWarningLimit: 4000, rollupOptions: { input: { index: pathResolve('./index.html', import.meta.url), }, // 静态资源分类打包 output: { chunkFileNames: 'static/js/[name]-[hash].js', entryFileNames: 'static/js/[name]-[hash].js', assetFileNames: 'static/[ext]/[name]-[hash].[ext]', }, }, }, ```
Owner

We are unable to reproduce it locally. However, since the two expressions are equivalent, we will make the change.

We are unable to reproduce it locally. However, since the two expressions are equivalent, we will make the change.
Sign in to join this conversation.
No Milestone
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: sheetjs/sheetjs#3219
No description provided.