diff --git a/addons/controls/src/preset/checkDocsLoaded.ts b/addons/controls/src/preset/checkDocsLoaded.ts index e7dd71e882a..e888487605e 100644 --- a/addons/controls/src/preset/checkDocsLoaded.ts +++ b/addons/controls/src/preset/checkDocsLoaded.ts @@ -1,4 +1,4 @@ -import { checkAddonOrder } from '@storybook/core-common'; +import { checkAddonOrder, serverRequire } from '@storybook/core-common'; import path from 'path'; export const checkDocsLoaded = (configDir: string) => { @@ -14,6 +14,6 @@ export const checkDocsLoaded = (configDir: string) => { configFile: path.isAbsolute(configDir) ? path.join(configDir, 'main') : path.join(process.cwd(), configDir, 'main'), - getConfig: (configFile) => import(configFile), + getConfig: (configFile) => serverRequire(configFile), }); }; diff --git a/addons/essentials/package.json b/addons/essentials/package.json index 74a170e1d1b..a07a1d64be3 100644 --- a/addons/essentials/package.json +++ b/addons/essentials/package.json @@ -49,6 +49,7 @@ "@storybook/addon-viewport": "6.5.0-alpha.41", "@storybook/addons": "6.5.0-alpha.41", "@storybook/api": "6.5.0-alpha.41", + "@storybook/core-common": "6.5.0-alpha.41", "@storybook/node-logger": "6.5.0-alpha.41", "core-js": "^3.8.2", "regenerator-runtime": "^0.13.7", diff --git a/addons/essentials/src/index.ts b/addons/essentials/src/index.ts index 21470e2b940..6a3fc4dbbf8 100644 --- a/addons/essentials/src/index.ts +++ b/addons/essentials/src/index.ts @@ -1,5 +1,6 @@ import path, { join } from 'path'; import { logger } from '@storybook/node-logger'; +import { serverRequire } from '@storybook/core-common'; interface PresetOptions { configDir?: string; @@ -9,25 +10,12 @@ interface PresetOptions { } const requireMain = (configDir: string) => { - let main = {}; const absoluteConfigDir = path.isAbsolute(configDir) ? configDir : path.join(process.cwd(), configDir); const mainFile = path.join(absoluteConfigDir, 'main'); - try { - // eslint-disable-next-line global-require,import/no-dynamic-require - main = require(mainFile); - } catch (err) { - try { - // Try finding a .cjs version of the main file - const mainFileCjs = path.join(absoluteConfigDir, 'main.cjs'); - // eslint-disable-next-line global-require,import/no-dynamic-require - main = require(mainFileCjs); - } catch (cjsErr) { - logger.warn(`Unable to find main.js or main.cjs: ${mainFile}`); - } - } - return main; + + return serverRequire(mainFile) ?? {}; }; export function addons(options: PresetOptions = {}) { diff --git a/addons/interactions/src/preset/checkActionsLoaded.ts b/addons/interactions/src/preset/checkActionsLoaded.ts index e38999fe8ed..3c0ca141457 100644 --- a/addons/interactions/src/preset/checkActionsLoaded.ts +++ b/addons/interactions/src/preset/checkActionsLoaded.ts @@ -1,4 +1,4 @@ -import { checkAddonOrder } from '@storybook/core-common'; +import { checkAddonOrder, serverRequire } from '@storybook/core-common'; import path from 'path'; export const checkActionsLoaded = (configDir: string) => { @@ -14,6 +14,6 @@ export const checkActionsLoaded = (configDir: string) => { configFile: path.isAbsolute(configDir) ? path.join(configDir, 'main') : path.join(process.cwd(), configDir, 'main'), - getConfig: (configFile) => import(configFile), + getConfig: (configFile) => serverRequire(configFile), }); }; diff --git a/yarn.lock b/yarn.lock index 4091555e415..5e2afa8772b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6527,6 +6527,7 @@ __metadata: "@storybook/addon-viewport": 6.5.0-alpha.41 "@storybook/addons": 6.5.0-alpha.41 "@storybook/api": 6.5.0-alpha.41 + "@storybook/core-common": 6.5.0-alpha.41 "@storybook/node-logger": 6.5.0-alpha.41 "@storybook/vue": 6.5.0-alpha.41 "@types/jest": ^26.0.16