diff --git a/lib/source-loader/package.json b/lib/source-loader/package.json index 5b540b028346..94c3619fd980 100644 --- a/lib/source-loader/package.json +++ b/lib/source-loader/package.json @@ -29,6 +29,7 @@ }, "dependencies": { "@storybook/addons": "5.2.7", + "@storybook/client-logger": "5.2.7", "@storybook/router": "5.2.7", "core-js": "^3.0.1", "estraverse": "^4.2.0", diff --git a/lib/source-loader/src/client/preview.js b/lib/source-loader/src/client/preview.js index 7a03d3f576bd..05491f18cf8b 100644 --- a/lib/source-loader/src/client/preview.js +++ b/lib/source-loader/src/client/preview.js @@ -1,4 +1,5 @@ import addons from '@storybook/addons'; +import { logger } from '@storybook/client-logger'; import { STORY_EVENT_ID } from './events'; const getLocation = (context, locationsMap) => locationsMap[context.id]; @@ -13,6 +14,14 @@ function sendEvent( prefix, idsToFrameworks ) { + if (!context || !context.id || !context.kind || !context.story) { + logger.warn( + '@storybook/source-loader was applied to a file which does not contain a story. Please check your webpack configuration and make sure to apply @storybook/source-loader only to files containg stories. Related file:' + ); + logger.warn(source); + return; + } + const channel = addons.getChannel(); const currentLocation = getLocation(context, locationsMap);