dfinity / agent-js

A collection of libraries and tools for building software around the Internet Computer, in JavaScript.

Home Page:https://agent-js.icp.xyz

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Bundling agent-js in a lib used webback projects leads to warnings

peterpeterparker opened this issue · comments

Is your feature request related to a problem? Please describe.
When agent-js is bundled within a lib that gets imported in Webpack projects, Webpack throws following errors:

Warning: Critical dependency: require function is used in a way in which dependencies cannot be statically extracted

Describe the solution you'd like
Don't think it is a bug but, I am guessing it is a Polyfill thing. Therefore would appreciate any help resolving this issue.

On the lib side, Node libraries are pollyfied. I tried to create a library that do not use agent-js but process and buffer and no such warning was displayed. Issue popups when agent-js gets bundled.

e.g. library I used for testing contains only following code:

import {isDelegationValid} from '@dfinity/identity';

export const yolo = () => {
    console.log(isDelegationValid);
}

Note: peer dependencies is not an option.

Additional context

Repro

  1. Build a sample lib
git clone https://github.com/peterpeterparker/polyfill-lib
cd polyfill-lib
npm ci
npm run build
  1. in any Webpack based project
npm it /path/to/local/polyfill-lib

add following in code

import {yolo} from "polyfill-lib";
console.log(yolo);

and build

npm run build

It seems that if I build the library with vite / rollup I don't face the issue. I guess something in the esbuild setup of the lib therefore I close this (at least for now, not 100% sure).

For the record, the type=module was missing in the package.json of my libs 🤦‍♂️