alt icon indicating copy to clipboard operation
alt copied to clipboard

Alt warnings in production mode

Open dpobozniak opened this issue 10 years ago • 12 comments

Hi, I use alt with react and webpack's uglifyjs plugin. After creating minified version of browserified js bundle, alt prints warnings in chrome's console:

ReferenceError: A store named e already exists, double check your store names or pass in your own custom identifier for each store(…)

Is it possible to not show warnings/errors when NODE_ENV is set to production, just like React has it now?

Many thanks.

dpobozniak avatar Dec 09 '15 08:12 dpobozniak

babel-plugin-dev-expression strips warnings, but it's not going to do anything for actual errors. Errors are errors, after all.

taion avatar Dec 09 '15 14:12 taion

It's possible yeah. I think if we move to npm package warn we get that for free.

goatslacker avatar Dec 09 '15 21:12 goatslacker

I'm thinking about stripping only warnings. babel-plugin-dev-expression does what React has implemented in their code, so it checks if process.env.NODE_ENV !== 'production', then shows warnings. Do you think it's better to use babel-plugin-dev-expression for it or you could do similarly to React? Thanks.

dpobozniak avatar Dec 10 '15 07:12 dpobozniak

doesn't the package warning do this?

goatslacker avatar Dec 10 '15 07:12 goatslacker

I mean if you could wrap your Alt warning messages in condition so they wouldn't be shown if NODE_ENV is set to production.

dpobozniak avatar Dec 10 '15 10:12 dpobozniak

warning doesn't log in production, but you need the Babel hook to strip out the calls and messages from production builds entirely.

taion avatar Dec 10 '15 14:12 taion

What Babel hook should I use then? I though that if I set NODE_ENV to production with webpack.DefinePlugin, I won't have any warnings visible.

dpobozniak avatar Dec 10 '15 14:12 dpobozniak

babel-plugin-dev-expression, like I mentioned, but the library should be running that Babel transform, not you.

taion avatar Dec 10 '15 14:12 taion

I installed babel-plugin-dev-expression (have it in devDependencies in package.json) and added .babelrc file:

{
  "stage": 0,
  "plugins": [
    "dev-expression"
  ]
}

Could you tell me what I'm doing wrong (I still have warnings)?

Thanks.

dpobozniak avatar Dec 11 '15 07:12 dpobozniak

It's not you, it's alt.

goatslacker avatar Dec 11 '15 07:12 goatslacker

I think it is not a good idea to hide warning/error, it's better to solve them.

alt store names are inferred from the store class name. Here, you 'uglifies' your js, that means that the class name could be change by the uglify tool. That way, you could have many stores with the same name and i think it is not a good idea…

When you create your store you can simply name it, makes it disappear this warning. (Something like export default alt.createStore(TheStoreClass, 'the_store');)

Sy1v4in avatar Jan 09 '16 14:01 Sy1v4in

@fraisse is correct. Provide a unique store name in the createStore method. Or, specify a static displayName in the store class, e.g. static displayName = 'the_store'.

mchiocca avatar May 31 '18 21:05 mchiocca