GoogleChrome / web-vitals

Essential metrics for a healthy site.
https://web.dev/vitals
Apache License 2.0
7.47k stars 410 forks source link

Facing issue while exporting `web-vitals/attribution` using `browserify` #486

Closed Archish27 closed 3 months ago

Archish27 commented 3 months ago

Unable to build using browserify when using

const {
  onCLS,
  onLCP,
  onFID,
  onINP,
  onFCP,
  onTTFB,
} = require("web-vitals/attribution");

Getting error while building browserify -

./node_modules/.bin/browserify -d  -t [ babelify --presets [ @babel/preset-env ] ] index.js > dist/bundle.js

/home/archish/code/agent-browser/node_modules/web-vitals/attribution.js:18
export * from './dist/web-vitals.attribution.js';
^
ParseError: 'import' and 'export' may appear only with 'sourceType: module'
Archish27 commented 3 months ago

Hey @tunetheweb,can you please help facing the above issue? Using Javascript with commonjs not using module.

tunetheweb commented 3 months ago

There's some suggestions here which seem to work from a quick test: https://stackoverflow.com/questions/51023231/npm-browserify-import-and-export-may-appear-only-with-sourcetype-module.

Alternatively you can use } = require("web-vitals/dist/web-vitals.attribution.iife.js"); or } = require("web-vitals/dist/web-vitals.attribution.umd.cjs"); in your code.

But ultimately this is a browserify issue and not a web-vitals issue as far as I can tell so closing this.