next-mf-blogpost icon indicating copy to clipboard operation
next-mf-blogpost copied to clipboard

Import is not working in app2

Open sankaran85 opened this issue 4 years ago • 4 comments

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 () at Object.webpack/container/reference/app1 (D:\react\nextjs-example\next-mf-blogpost\app2.next\server\pages\index.js:2052:18) at webpack_require (D:\react\nextjs-example\next-mf-blogpost\app2.next\server\webpack-runtime.js:24:42) at handleFunction (D:\react\nextjs-example\next-mf-blogpost\app2.next\server\webpack-runtime.js:173:31) at D:\react\nextjs-example\next-mf-blogpost\app2.next\server\webpack-runtime.js:192:15 code: 'MODULE_NOT_FOUND' } event - build page: /next/dist/pages/_error

sankaran85 avatar Dec 08 '20 14:12 sankaran85

I am getting the same behavior. @sankaran85 did you find any way around this ?

bchurlinov avatar Dec 16 '20 07:12 bchurlinov

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.

hamatoyogi avatar Feb 22 '21 11:02 hamatoyogi

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.

bobum avatar Jun 24 '21 07:06 bobum

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
      },

AnilDCoder avatar Nov 25 '21 06:11 AnilDCoder