I run my next.js app on localhost:3001
. I want to fetch script from another host (localhost:3000
). I could do it like this. As for me, much prettier would be using dynamic import
. But I got an error: 'ModuleNotFoundError: Module not found: Error: Can't resolve 'http://localhost:3000/static/fileToFetch.js' in '/Users/{username}/Desktop/test-project/pages';
Example:
export const FetchedComponent = dynamic({
loader: () =>
import('http://localhost:3000/static/fileToFetch.js'),
loading: () => 'Loading...',
ssr: false,
});
Is it possible to do it?