diff --git a/src/ssr/ssr-module.ts b/src/ssr/ssr-module.ts index 7c943cf2..28a32cd9 100644 --- a/src/ssr/ssr-module.ts +++ b/src/ssr/ssr-module.ts @@ -11,13 +11,13 @@ export const SSRModule = (config: string | InjectableConfig & { name: string }) let name: string if (typeof config === 'string') { if (configSets.has(config)) { - throw new Error(`Duplicated Module name: ${config}`) + reportDuplicated(config) } name = config configSets.add(config) } else if (config && typeof config.name === 'string') { if (configSets.has(config.name)) { - throw new Error(`Duplicated Module name: ${config.name}`) + reportDuplicated(config.name) } configSets.add(config.name) name = config.name @@ -33,3 +33,11 @@ export const SSRModule = (config: string | InjectableConfig & { name: string }) return Injectable(injectableConfig)(target) } } + +function reportDuplicated(moduleName: string) { + if (process.env.NODE_ENV === 'production') { + throw new Error(`Duplicated Module name: ${moduleName}`) + } + // avoid to throw error after HMR + console.warn(`Duplicated Module name: ${moduleName}`) +} diff --git a/test/specs/ssr.spec.tsx b/test/specs/ssr.spec.tsx index 0cf11960..f52c55d5 100644 --- a/test/specs/ssr.spec.tsx +++ b/test/specs/ssr.spec.tsx @@ -107,11 +107,13 @@ describe('SSR specs:', () => { beforeAll(() => { // @ts-ignore process.env.ENABLE_AYANAMI_SSR = 'true' + process.env.NODE_ENV = 'production' }) afterAll(() => { // @ts-ignore process.env.ENABLE_AYANAMI_SSR = 'false' + delete process.env.NODE_ENV }) it('should throw if module name not given', () => { @@ -172,6 +174,9 @@ describe('SSR specs:', () => { expect(generateException1).toThrow() expect(generateException2).toThrow() expect(generateException3).toThrow() + process.env.NODE_ENV = 'development' + expect(generateException1).not.toThrow() + expect(generateException2).not.toThrow() }) it('should run ssr effects', async () => {