Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[now] nestjs error: cannot find module @nodelib/fs.stat #3115

Closed
iivankin opened this issue Oct 2, 2019 · 19 comments
Closed

[now] nestjs error: cannot find module @nodelib/fs.stat #3115

iivankin opened this issue Oct 2, 2019 · 19 comments
Labels
area: node triaged: bug Issue or PR has been reviewed by a maintainer and work is being tracked

Comments

@iivankin
Copy link

iivankin commented Oct 2, 2019

I'm trying to deploy nestjs server.
Few days ago it worked fine, but now i get this error:


SyntaxError: Unexpected token (16:10)
09:39:17 PM | at Object.re.raise (evalmachine.<anonymous>:1:266416)
09:39:17 PM | at Object.z.unexpected (evalmachine.<anonymous>:1:222693)
09:39:17 PM | at Object.ee.parseIdent (evalmachine.<anonymous>:1:265599)
09:39:17 PM | at Object.parseIdent (evalmachine.<anonymous>:1:461728)
09:39:17 PM | at Object.parseIdent (evalmachine.<anonymous>:1:186548)
09:39:17 PM | at Object.ee.parsePropertyName (evalmachine.<anonymous>:1:261995)
09:39:17 PM | at Object.parsePropertyName (evalmachine.<anonymous>:1:4333)
09:39:17 PM | at Object.H.parseClassElement (evalmachine.<anonymous>:1:236905)
09:39:17 PM | at Object.parseClassElement (evalmachine.<anonymous>:1:459918)
09:39:17 PM | at Object.parseClassElement (evalmachine.<anonymous>:1:183081)
09:39:17 PM | Module build failed (from /tmp/ef2c4852ec461ae6/.build-utils/.builder/node_modules/@zeit/ncc/dist/ncc/loaders/relocate-loader.js):
09:39:17 PM | SyntaxError: Unexpected token (15:10)
09:39:17 PM | at Object.re.raise (evalmachine.<anonymous>:1:266416)
09:39:17 PM | at Object.z.unexpected (evalmachine.<anonymous>:1:222693)
09:39:17 PM | at Object.ee.parseIdent (evalmachine.<anonymous>:1:265599)
09:39:17 PM | at Object.parseIdent (evalmachine.<anonymous>:1:461728)
09:39:17 PM | at Object.parseIdent (evalmachine.<anonymous>:1:186548)
09:39:17 PM | at Object.ee.parsePropertyName (evalmachine.<anonymous>:1:261995)
09:39:17 PM | at Object.parsePropertyName (evalmachine.<anonymous>:1:4333)
09:39:17 PM | at Object.H.parseClassElement (evalmachine.<anonymous>:1:236905)
09:39:17 PM | at Object.parseClassElement (evalmachine.<anonymous>:1:459918)
09:39:17 PM | at Object.parseClassElement (evalmachine.<anonymous>:1:183081)
09:39:17 PM | at compiler.close.n (evalmachine.<anonymous>:3:1350338)
09:39:17 PM | at _promise0.then._result0 (eval at create (evalmachine.<anonymous>:1:349386), <anonymous>:13:1)
09:39:17 PM | at <anonymous>

now.json:

{
    "name": "super-cool-project-name",
    "builds": [
        { "src": "index.js", "use": "@now/node-server" }
    ],
    "routes": [
        {
            "headers": {
                "Access-Control-Allow-Origin": "*",
                "Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, OPTIONS",
                "Access-Control-Allow-Headers": "X-Requested-With, Content-Type, Accept"
            },
            "src": "/.*",
            "dest": "/index.js"
        }
    ]
}

index.js:

require('ts-node')
require('tsconfig-paths/register');
require('./src/main');

any ideas?

@styfle
Copy link
Member

styfle commented Oct 3, 2019

Hi @cheel1337

The @now/node-server builder is deprecated.

Please use @now/node instead (it will work with the same API). Thanks!

@iivankin
Copy link
Author

iivankin commented Oct 3, 2019

Hi @styfle

Now i get this:

Error: src/main.ts(28,9): error TS2349: This expression is not callable.
08:35:09 PM | Type 'typeof session' has no call signatures.
08:35:09 PM | src/main.ts(43,13): error TS2349: This expression is not callable.
08:35:09 PM | Type '{ default: Helmet; contentSecurityPolicy(options?: IHelmetContentSecurityPolicyConfiguration): RequestHandler; dnsPrefetchControl(options?: IHelmetDnsPrefetchControlConfiguration): RequestHandler; ... 10 more ...; permittedCrossDomainPolicies(options?: IHelmetPermittedCrossDomainPoliciesConfiguration): RequestHandle...' has no call signatures.
08:35:09 PM |  

I only change @now/node-server to @now/node.

@styfle styfle added the question label Oct 3, 2019
@styfle
Copy link
Member

styfle commented Oct 3, 2019

You can remove ts-node since ZEIT Now will already work with typescript.

Your error message makes me think you're missing @types/helmet or some typings.

Try using the typescript file as the entry point:

{
    "name": "example",
    "builds": [
        { "src": "index.ts", "use": "@now/node" }
    ],
    "routes": [
        {  "src": "/.*", "/index.ts" }
    ]
}

@styfle styfle changed the title [now] error when deploying to prod [now] error when deploying nestjs typescript server Oct 3, 2019
@iivankin
Copy link
Author

iivankin commented Oct 3, 2019

@styfle

I have @types/helmet
Error comes from this lines:

import * as session from 'express-session';
...
app.use(
        session({
            ...
        })
    );

And this:

app.use(helmet());

@styfle
Copy link
Member

styfle commented Oct 3, 2019

Does it build with tsc?

What is the contents of tsconfig.json?

@iivankin
Copy link
Author

iivankin commented Oct 4, 2019

@styfle

Ok, i fixed it. Now it doesn't show any errors. But..
During the build, he does not install any deps
And the build is going very fast

Installing build runtime...
06:56:02 PM | Build runtime installed: 890.302ms
06:56:03 PM | Looking up build cache...
06:56:14 PM | Build cache unpacked: 11524.224ms
06:56:15 PM | Installing dependencies...
06:56:15 PM | yarn install v1.17.3
06:56:15 PM | [1/4] Resolving packages...
06:56:16 PM | success Already up-to-date.
06:56:16 PM | Done in 0.47s.
06:56:45 PM | Build completed. Populating build cache...
06:57:20 PM | Build cache uploaded [34.62 MB]: 17623.561ms
06:57:20 PM | done

And in runtime logs it spams:

2019-10-04T15:57:06.991Z	02608719-f996-4679-b6d8-6dae0996c3f8	Cannot find module '@nodelib/fs.stat'
2019-10-04T15:57:06.992Z	02608719-f996-4679-b6d8-6dae0996c3f8	Did you forget to add it to "dependencies" in `package.json`?
Duration: 1093.52 ms  Billed Duration: 1100 ms  Memory Size: 3008 MB  Max Memory Used: 122 MB	
RequestId: 02608719-f996-4679-b6d8-6dae0996c3f8 Process exited before completing request

now.json:

{
  "name": "name",
  "builds": [
    {
      "src": "dist/main.js",
      "use": "@now/node"
    }
  ],
  "routes": [
    {
      "src": "/(.*)",
      "dest": "/dist/main.js"
    }
  ]
}

Deploying with: tsc && now --prod

@styfle
Copy link
Member

styfle commented Oct 4, 2019

I see.

The @nodelib/fs.stat error is likely from fast-glob and globby tracked here vercel/nft#55

If you can replace that dependency with a different glob implementation, it should work.

@iivankin
Copy link
Author

iivankin commented Oct 4, 2019

This dependency is used in @nestjs/graphql

@AryanJ-NYC
Copy link

AryanJ-NYC commented Oct 7, 2019

I am also trying to deploy a NestJS server using @now/node:

{
  "version": 2,
  "name": "stuffs",
  "builds": [
    {
      "src": "dist/apps/backend/main.js",
      "use": "@now/node"
    }
  ],
  "routes": [
    {
      "src": "/(.*)",
      "dest": "dist/apps/backend/main.js"
    }
  ]
}

Am getting a similar error as @cheel1337:

START RequestId: d684c95f-7a70-4d34-80b5-34872b971e5d Version: $LATEST
2019-10-07T01:00:15.717Z	d684c95f-7a70-4d34-80b5-34872b971e5d	Cannot find module '@nodelib/fs.stat'
2019-10-07T01:00:15.718Z	d684c95f-7a70-4d34-80b5-34872b971e5d	Did you forget to add it to "dependencies" in `package.json`?
END RequestId: d684c95f-7a70-4d34-80b5-34872b971e5d
REPORT RequestId: d684c95f-7a70-4d34-80b5-34872b971e5d	Duration: 798.15 ms	Billed Duration: 800 ms	Memory Size: 3008 MB	Max Memory Used: 106 MB	
RequestId: d684c95f-7a70-4d34-80b5-34872b971e5d Process exited before completing request

Just thought I'd add a data point here and perhaps some help in debugging in getting this fixed.

@styfle styfle changed the title [now] error when deploying nestjs typescript server [now] nestjs error: cannot find module @nodelib/fs.stat Oct 7, 2019
@styfle styfle added area: node triaged: bug Issue or PR has been reviewed by a maintainer and work is being tracked and removed question labels Oct 7, 2019
@iivankin
Copy link
Author

@styfle When will it be fixed?

@elvenking
Copy link

@styfle Can you please comment if there is any progress ?

@iivankin
Copy link
Author

Recently i opened issue here and get nothing :(

@elvenking
Copy link

@cheel1337

I fixed it on my side:

I was using graphql-modules & graphql-toolkit packages together. Unfortunately there was a recent change in how graphql-toolkit is published on npmjs.com
Urigo/graphql-modules@eecfc52

So i basically started depending on prefixed packages and it works now !

'graphql-toolkit' -> '@graphql-toolkit/file-loading'

@iivankin
Copy link
Author

@elvenking I do not use any of this. You can see my reproduction repo

@elvenking
Copy link

@cheel1337

yarn why v1.19.1
[1/4] 🤔 Why do we have the module "graphql-toolkit"...?
[2/4] 🚚 Initialising dependency graph...
[3/4] 🔍 Finding dependency...
[4/4] 🚡 Calculating file sizes...
=> Found "graphql-toolkit@0.5.0"
info Reasons this module exists

  • "@nestjs#graphql#merge-graphql-schemas" depends on it
  • Hoisted from "@nestjs#graphql#merge-graphql-schemas#graphql-toolkit"
    info Disk size without dependencies: "1.25MB"
    info Disk size with unique dependencies: "7.63MB"
    info Disk size with transitive dependencies: "10.78MB"
    info Number of shared dependencies: 29
    ✨ Done in 0.55s.

You are using it as a transitive dependency. I am not sure if it helps in your case, but i resolved the same (similar) issue just by redefining dependency on graphql-toolkit.

@AryanJ-NYC
Copy link

AryanJ-NYC commented Nov 19, 2019

@elvenking How did you redefine the graphql-toolkit dependency?

Edit: Redefined graphql-toolkit dependency by adding (to package.json)

  "resolutions": {
    "@nestjs/graphql/merge-graphql-schemas": "1.7.3"
  }

I'm still getting the same error:

2019-11-19T05:03:09.945Z	bc154607-cc58-4056-9019-704307d29e29	Cannot find module '@nodelib/fs.stat'
2019-11-19T05:03:09.945Z	bc154607-cc58-4056-9019-704307d29e29	Did you forget to add it to "dependencies" in `package.json`?
Duration: 831.71 ms  Billed Duration: 900 ms  Memory Size: 3008 MB  Max Memory Used: 111 MB	
RequestId: bc154607-cc58-4056-9019-704307d29e29 Process exited before completing request

@elvenking
Copy link

elvenking commented Nov 20, 2019

@AryanJ-NYC

I was using 'graphql-toolkit' as an direct dependency of my project.
So the change was like 'graphql-toolkit' -> '@graphql-toolkit/file-loading'

EDIT:
My project does not use NestJS. But the core issue "cannot find module @nodelib/fs.stat" was the same.

@ahrbil
Copy link

ahrbil commented Dec 26, 2019

I'm using graphql-tools for loading and merging .graphql files and I'm getting the same error on zeit now.
even when I have changed @graphql-toolkit/file-loading as @elvenking said.

@styfle
Copy link
Member

styfle commented Mar 2, 2020

This was fixed in vercel/nft#55 and then #3613.

@styfle styfle closed this as completed Mar 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: node triaged: bug Issue or PR has been reviewed by a maintainer and work is being tracked
Projects
None yet
Development

No branches or pull requests

5 participants