diff --git a/package.json b/package.json index 16d1203..ea632a0 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ }, "devDependencies": { "@babel/core": "^7.20.12", - "@loadable/babel-plugin": "^5.15.3", + "@loadable/babel-plugin": "^5.16.1", "@loadable/component": "^5.16.2", "@loadable/server": "^5.16.2", "@loadable/webpack-plugin": "^5.15.2", diff --git a/src/next-dynamic-loadable-shim.tsx b/src/next-dynamic-loadable-shim.tsx index 389955e..d8b775f 100644 --- a/src/next-dynamic-loadable-shim.tsx +++ b/src/next-dynamic-loadable-shim.tsx @@ -33,18 +33,13 @@ export default function ( // so the following is a bit hacky but allows us to preload all promises before rendering // and then return the right component in `resolveComponent`. const possiblePromise = - typeof dynamicImport === 'function' - ? // @ts-ignore - dynamicImport() - : 'requireSync' in dynamicImport - ? // @ts-ignore - dynamicImport.requireSync() - : undefined - if (typeof possiblePromise === 'undefined') { + // @ts-ignore + 'requireSync' in dynamicImport && dynamicImport.requireSync() + if (!possiblePromise) { throw new Error( `[next-static] Unable to convert dynamic import of ${String( possiblePromise - )}.` + )}. Please make sure you have the latest version (>= 5.16.1 of \`@loadable/babel-plugin\`) installed` ) } if (possiblePromise.then) { diff --git a/src_cjs/babel/index.ts b/src_cjs/babel/index.ts index 2e0d8cb..ccba0a7 100644 --- a/src_cjs/babel/index.ts +++ b/src_cjs/babel/index.ts @@ -8,7 +8,7 @@ export default (api: any, options?: any): any => { plugins: [ [ require('@loadable/babel-plugin'), - { defaultImportSpecifier: 'dynamic' }, + { signatures: [{name: 'default', from: 'next/dynamic'}] }, ], ...(result.plugins?.filter((plugin) => { return plugin.default !== loadablePlugin diff --git a/yarn.lock b/yarn.lock index e1ed6a6..d2b4a3f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -448,7 +448,7 @@ __metadata: resolution: "@freshcells/next-static-components@workspace:." dependencies: "@babel/core": ^7.20.12 - "@loadable/babel-plugin": ^5.15.3 + "@loadable/babel-plugin": ^5.16.1 "@loadable/component": ^5.16.2 "@loadable/server": ^5.16.2 "@loadable/webpack-plugin": ^5.15.2 @@ -849,14 +849,14 @@ __metadata: languageName: node linkType: hard -"@loadable/babel-plugin@npm:^5.15.3": - version: 5.15.3 - resolution: "@loadable/babel-plugin@npm:5.15.3" +"@loadable/babel-plugin@npm:^5.16.1": + version: 5.16.1 + resolution: "@loadable/babel-plugin@npm:5.16.1" dependencies: - "@babel/plugin-syntax-dynamic-import": "npm:^7.7.4" + "@babel/plugin-syntax-dynamic-import": ^7.7.4 peerDependencies: "@babel/core": ^7.0.0-0 - checksum: bea73fb9019e2b5d7418b52cfb63abd6838291ccc2ad64f65c7c17ff7eb1dae5dc4b471cf9a1df39a89cc8ab6fdfac47cae66f1d9827cb91478416708b96bbb9 + checksum: f7a1eed76ca6749d66f44d5d690c5812870cda7005fb02ac31135ad99d444d73919c3d31cbbcd94c7c9444641161406b4c42e44a9fee479f533ffafc62f8ad58 languageName: node linkType: hard