sticky-observer icon indicating copy to clipboard operation
sticky-observer copied to clipboard

Failed to load module

Open cjies opened this issue 6 years ago • 2 comments

Problem

Webpack will read browser field and ignoring main and module entry. And because of the bundle of "browser" version is using iife format, module script doesn't able to resolve the module correctly.

import { StickyObserver } from '@welt/sticky-observer';

console.log(StickyObserver); // undefined

Expected behavior

Should only use the main CJS field if available, or even module, literally everything but the browser one.

Reference

webpack/webpack#7646

cjies avatar Aug 06 '19 12:08 cjies

This issue happened in v1.1.0, and caused by #8. If downgrade to v1.0.0, module can be resolved correctly.

cjies avatar Aug 06 '19 12:08 cjies

Yes I had the same issue. You can workaround it with the this webpack config: https://webpack.js.org/configuration/resolve/#resolvemainfields

I use mainFields: ['module', 'main']. For the future I consider to remove the UMD bundle & browser field

bobaaaaa avatar Aug 06 '19 13:08 bobaaaaa