GoogleChromeLabs / perf-track

Tracking framework performance and usage at scale
https://perf-track.web.app/
Apache License 2.0
150 stars 12 forks source link

Fix ES module issues #25

Open ctjlewis opened 3 years ago

ctjlewis commented 3 years ago

Currently:

import { data } from './perf-track/src/page-data/may-2020/react.js';

Will throw:

import { data } from './perf-track/src/page-data/may-2020/react.js';
         ^^^^
SyntaxError: Named export 'data' not found. The requested module './perf-track/src/page-data/may-2020/react.js' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from './perf-track/src/page-data/may-2020/react.js';
const { data } = pkg;

    at ModuleJob._instantiate (internal/modules/esm/module_job.js:98:21)
    at async ModuleJob.run (internal/modules/esm/module_job.js:143:5)
    at async Loader.import (internal/modules/esm/loader.js:165:24)
    at async Object.loadESM (internal/process/esm_loader.js:68:5)

Because the Node module resolution algorithm checks perf-track/package.json, sees that it is not marked with "type": "module", and treats it as CJS.

This PR makes a quick change to explicitly declare the package as an ES module.

Footnotes

Also, import statements like import { namedImport } from './my-relative-path/entry.js' require file extensions if the file has a file extension (entry will not resolve to entry.js). Simply adding the necessary .js extensions allows JS clients to execute the source as-is, without precompiling with Rollup.

housseindjirdeh commented 3 years ago

This is great, thank you!

Apologies, but I've restructured the app a little and removed earlier datasets in favor of November data (should have merged this in first - my bad!). If you can update this to reflect that, we'll get this in 🚀