doesdev / rollup-plugin-analyzer

Mad metrics for your rollup bundles, know all the things

Home Page:http://rollup-plugin-analyzer.doesdev.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Doesn't work.

joeyhub opened this issue · comments

commented
npm install rollup-plugin-analyzer
import analyzerPlugin from 'rollup-plugin-analyzer';
analyzerPlugin();
(node:9194) UnhandledPromiseRejectionWarning: TypeError: analyzerPlugin is not a function

It may be that your example isn't reflective of your actual usage, but assuming it is then you'll need to make some changes.

Since this is a plugin for rollup you will need to call it within the plugins array of the rollup options.

Like so:

import { rollup } from 'rollup'
import analyze from 'rollup-plugin-analyzer'

rollup({
  entry: 'main.js',
  plugins: [analyze()]
}).then(...)

If that is how you're using it and it isn't working please let me know. I'll close this for now though.

commented
# (node --version;npm install rollup-plugin-analyzer;echo 'import analyzerPlugin from "rollup-plugin-analyzer";analyzerPlugin();' > test.mjs;node --experimental-modules test.mjs)
v12.10.0
+ rollup-plugin-analyzer@3.1.2
(node:9412) ExperimentalWarning: The ESM module loader is experimental.
file:///beancount/test.mjs:1
import analyzerPlugin from "rollup-plugin-analyzer";analyzerPlugin();
                                                    ^

TypeError: analyzerPlugin is not a function
    at file:///beancount/test.mjs:1:53
    at ModuleJob.run (internal/modules/esm/module_job.js:111:37)
    at async Loader.import (internal/modules/esm/loader.js:137:24)

Other plugins work. It's just this one.

commented

You plugin is structured differently to others so it can't import somehow.

Even the module.js wont parse (since not mjs or some other convention)...

export const reporter = (analysis, opts) => {
^^^^^^

SyntaxError: Unexpected token export
commented

Other modules seem to follow a fairly consistent pattern of including a dist along with src.

Then in the dist...

"main": "dist/rollup-plugin-commonjs.cjs.js",
"module": "dist/rollup-plugin-commonjs.es.js",

Though some also just use module for what's in src and then put a legacy cjs in dist.

I still don't see why it doesn't work as you have these two fields in your package.json.

Renaming it to mjs worked. There's probably something weird in your package.json.

It complies with Node's specifications, but ESM support is still pretty unstable in Node so I guess it working only with the mjs extension is a reflection of that.

All the same the core problem isn't extension and was rather a bad export signature on my part. Just released 3.2.0 which corrects that.

commented

It works with module.exports instead of exports.