storybook: Unexpected token delete with addon-actions
I’m using the alpha version.
import { action } from '@storybook/addon-actions';
// ...later, in some story...
action('delete');
This results in the following error:
SyntaxError: Unexpected token delete
at action (node_modules/@storybook/addon-actions/dist/preview.js:59:42)
at Object.<anonymous> (web/static/js/sidebar/document.stories.js:19:38)
at node_modules/@storybook/addon-storyshots/dist/require_context.js:39:24
at Array.forEach (native)
at requireModules (node_modules/@storybook/addon-storyshots/dist/require_context.js:34:9)
at node_modules/@storybook/addon-storyshots/dist/require_context.js:48:7
at Array.forEach (native)
at requireModules (node_modules/@storybook/addon-storyshots/dist/require_context.js:34:9)
at Function.newRequire.context (node_modules/@storybook/addon-storyshots/dist/require_context.js:90:5)
at evalmachine.<anonymous>:23:21
at runWithRequireContext (node_modules/@storybook/addon-storyshots/dist/require_context.js:102:3)
at testStorySnapshots (node_modules/@storybook/addon-storyshots/dist/index.js:94:35)
at Object.<anonymous> (web/static/js/storyshots.test.js:5:31)
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 21 (13 by maintainers)
Thanks! I have no problem changing this to a non-reserved word, it just took me a while to realize what’s wrong, 😅 I wanted to create this issue so that other users figure this out more easily.
Thanks for all your hard work on Storybook! ❤️ 🍻
Fixed in
3.2.16In that case a prefix like
_could be a good middle-ground ? The actions would still appear named in the debug tools (but with an extra prefix) and no crash would occur for names that are forbidden in the function declaration (likedelete).Another solution I can think of is to put the
evalin atry/catchand then add the prefix only when necessary, but that gets quite ugly.Good point @gouegd!
After some hunting, I discovered the rationale: https://github.com/storybooks/storybook-addon-actions/pull/24