next-mf-blogpost
next-mf-blogpost copied to clipboard
Import is not working in app2
Hi,
when i try to run the app2 both console and in browser im getting below error. Please help me out.
Cannot find module 'D:extjs-exampleemoteEntry.js'tapp1.nextserverstatic
while loading "./nav" from webpack/container/reference/app1
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
at Function.Module._load (internal/modules/cjs/loader.js:562:25)
at Module.require (internal/modules/cjs/loader.js:692:17)
at require (internal/modules/cjs/helpers.js:25:18)
at module.exports.exports.modules.webpack/container/reference/app1.module.exports.res (D:\react\nextjs-example\next-mf-blogpost\app2.next\server\pages\index.js:2058:16)
at new Promise (
I am getting the same behavior. @sankaran85 did you find any way around this ?
I've just cloned the repo for a fresh start and re-tried it. Seems to work for me.
What version node are you trying @sankaran85 @bchurlinov?
Works for me at the moment on Node v14.7.0
.
The problem is pathing, at least on Windows. There is a require in the built index.js of app2 that isn't escaping the slashes in the path correctly and the required module thus can't be found. The \r and \n are getting treated as carriage returns and linefeeds - look at the error message and you can see it.
To fix it for me, did a manual 'yarn next build' of app 2 first. Then I went into the index.js where the error was getting thrown and found the following path in a require
remote = require('D:\projects\next-mf-blogpost\app1\.next\server\static\runtime\remoteEntry.js')['app1']
I changed that path to:
D:\\projects\\next-mf-blogpost\\app1\\.next\\server\\static\\runtime\\remoteEntry.js
In both the TRY and CATCH blocks.
Then I did a manual start of the server by running 'yarn next start -p 3001'
And poof it worked...haven't figured out yet how to fix it during the build process - but this got it up and running locally.
I fixed it by adding replace()
remotes: {
// For SSR, resolve to disk path (or you can use code streaming if you have access)
home: isServer
? path.resolve(
__dirname,
"../home/.next/server/static/runtime/remoteEntry.js"
).replace(/\\/g, '/') //<=====here
: "home", // for client, treat it as a global
},