SheetJS / sheetjs

📗 SheetJS Spreadsheet Data Toolkit -- New home https://git.sheetjs.com/SheetJS/sheetjs
https://sheetjs.com/
Apache License 2.0
34.73k stars 7.99k forks source link

Rollup: missing export of Buffer #2367

Closed alokekantal closed 2 years ago

alokekantal commented 2 years ago

NOTE: if you are using stencil with rollup-plugin-node-polyfills, pass an exclude option

I got the bellow error when I use xlsx module with stenciljs with MAC machine. Module is working fine in windows. Rollup: Missing Export: ./node_modules/xlsx/dist/cpexcel.js:1:9

'Buffer' is not exported by node-resolve:empty.js, imported by

./node_modules/xlsx/dist/cpexcel.js

L1: /! cpexcel.js (C) 2013-present SheetJS -- http://sheetjs.com /

L2: /jshint -W100 /

Thanks in advance

reviewher commented 2 years ago

https://github.com/SheetJS/sheetjs/tree/master/demos/rollup#required-plugins mentions some override:

import resolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
export default {
    /* ... */
    plugins: [
        resolve({
            module: false, // <-- this library is not an ES6 module
            browser: true, // <-- suppress node-specific features
        }),
        commonjs()
    ],
    /* ... */
};

Does that help?

alokekantal commented 2 years ago

Is this is separate config file?

alokekantal commented 2 years ago

Getting same issue. I added the above plugins in stencil.config.ts file.

dsubiros commented 2 years ago

Hello guys:

I'm using Ubuntu 20.04, and I'm having the same issue. Any solution available yet?

Thanks!

SheetJSDev commented 2 years ago

If there is an operating system problem, the issue almost lies with with the tooling. In this case, you should raise an issue in the StencilJS bug tracker. For example, https://github.com/ionic-team/stencil/issues/2610 is a similar case where something worked in Windows but not in Ubuntu.

But to be sure it isn't a SheetJS issue, a test was run on OSX Catalina 10.15.7 using npm init stencil to create an "app". src/components/app-home/app-home.tsx was changed to import and use the library:

import { Component, h } from '@stencil/core';
import { read } from 'xlsx';
const data = read("abc,def\nghi,jkl", {type: "string"}).Sheets.Sheet1.A1.v

@Component({
  tag: 'app-home',
  styleUrl: 'app-home.css',
  shadow: true,
})
export class AppHome {
  render() {
    return (
      <div class="app-home">
        <p>
          {data}
        </p>
      </div>
    );
  }
}

There is no rollup message in the hot reload (npm start) and no warning in the build step (npm run build)

MarkChrisLevy commented 2 years ago

The issue exists when rollup-plugin-node-polyfills is added to stencil.conf.js. Simple fix is to call nodePolyfills with additional options parameter and exclude sheetjs, e.g. stencil.conf.js:

{
...
   rollupPlugins: {
      after: [nodePolyfills({exclude: ["node_modules/xlsx/**"]})]
   }
...
}
SheetJSDev commented 2 years ago

Thanks @MarkChrisLevy , the issue can be reproduced using that plugin and your solution works. Unfortunately that option is not in the plugin docs :(

The raw rollup demo works with the polyfills plugin, probably because it also uses rollup-plugin-node-resolve (now @rollup/plugin-node-resolve)