Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: Cannot find module 'require("./server/main")' in angular firebase universal

This is error on cmd npm run serve:ssr

 I'm getting the error 'Can't find module 'require("./server/main") while hit the command "npm run server:ssr".
    but "npm run build:ssr" execute successfully.
    Please Help anyone.

    PS C:\Users\DELL\ion\portfolio\portfolio> npm run serve:ssr

    > [email protected] serve:ssr C:\Users\DELL\ion\portfolio\portfolio
    > node dist/server

    internal/modules/cjs/loader.js:628
        throw err;
        ^

    Error: Cannot find module 'require("./server/main")'
    Require stack:
    - C:\Users\DELL\ion\portfolio\portfolio\dist\server.js
        at Function.Module._resolveFilename (internal/modules/cjs/loader.js:625:15)
        at Function.Module._load (internal/modules/cjs/loader.js:527:27)
        at Module.require (internal/modules/cjs/loader.js:683:19)
        at require (internal/modules/cjs/helpers.js:16:16)
        at webpackUniversalModuleDefinition 
        (C:\Users\DELL\ion\portfolio\portfolio\dist\server.js:3:28)
        at Object.<anonymous> 
        (C:\Users\DELL\ion\portfolio\portfolio\dist\server.js:10:3)
        at Module._compile (internal/modules/cjs/loader.js:776:30)
        at Object.Module._extensions..js 
       (internal/modules/cjs/loader.js:787:10)
        at Module.load (internal/modules/cjs/loader.js:643:32)
        at Function.Module._load (internal/modules/cjs/loader.js:556:12) 
     {
      code: 'MODULE_NOT_FOUND',
      requireStack: [ 
    'C:\\Users\\DELL\\ion\\portfolio\\portfolio\\dist\\server.js' ]
    }

I have also tried to use import instead of const in server.ts file

    npm ERR! code ELIFECYCLE
    npm ERR! errno 1
    npm ERR! [email protected] serve:ssr: `node dist/server`
    npm ERR! Exit status 1
    npm ERR!
    npm ERR! Failed at the [email protected] serve:ssr script.
    npm ERR! This is probably not a problem with npm. There is likely 
    additional logging output above.

    npm ERR! A complete log of this run can be found in:
    npm ERR!     C:\Users\DELL\AppData\Roaming\npm-cache\_logs\2019-08- 
    31T17_48_40_065Z-debug.log

please help me out of this problem this is the last step in angular firebase universal

like image 238
Aman Gupta Avatar asked Nov 16 '22 02:11

Aman Gupta


1 Answers

I was receiving the same error and tracked it down to a couple of lines in webpack.server.config.js

  externals: {
    './dist/server/main': 'require("./server/main")'
  },

commenting those out increased my bundle size a bit, but I no longer receive that error in my Lambda function. I haven't figured out why that causes an error yet, but maybe it will get you going again until we can find out why.

like image 135
Philip Senechal Avatar answered Dec 05 '22 19:12

Philip Senechal