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

Build fails using adapter-vercel #7245

Closed
CalebBassham opened this issue Oct 12, 2022 · 16 comments · Fixed by #7312
Closed

Build fails using adapter-vercel #7245

CalebBassham opened this issue Oct 12, 2022 · 16 comments · Fixed by #7312
Labels
awaiting submitter pkg:adapter-vercel Pertaining to the Vercel adapter

Comments

@CalebBassham
Copy link

CalebBassham commented Oct 12, 2022

Describe the bug

I am working on updating one of my apps (from 367). Finally got it all working in pnpm dev, so I go to build and... fail. I have been racking my brain but unfortunately I haven't been able to pin down exactly why. It seems that it is something with the adapter itself, but obviously not all adapter-vercel builds are failing, so maybe it is something on my end. Ahh! 😕 Maybe this has been seen before and there is a known solution? 🤞🏻

The vite part of the build works fine, so pnpm preview works, just not the final build. I have also tried building with adapter-node which worked as expected and even adapter-netlify which worked, although I did not deploy it.

Reproduction

Sorry, no repro. I have not been able to pin down exactly what is causing this. Feel free to close I guess but just frustrating since I deploy to vercel. I would just say it is obviously something on my end, but it is weird that adapter-node and adapter-netlify build successfully if that is the case.

Logs

error during build:
TypeError: object null is not iterable (cannot read property Symbol(Symbol.iterator))
    at file:///Users/caleb/repos/[redacted]/node_modules/.pnpm/@sveltejs+adapter-vercel@1.0.0-next.78/node_modules/@sveltejs/adapter-vercel/index.js:318:33
    at Set.forEach (<anonymous>)
    at create_function_bundle (file:///Users/caleb/repos/[redacted]/node_modules/.pnpm/@sveltejs+adapter-vercel@1.0.0-next.78/node_modules/@sveltejs/adapter-vercel/index.js:307:18)
    at async generate_serverless_function (file:///Users/caleb/repos/[redacted]/node_modules/.pnpm/@sveltejs+adapter-vercel@1.0.0-next.78/node_modules/@sveltejs/adapter-vercel/index.js:153:5)
    at async adapt (file:///Users/caleb/repos/[redacted]/node_modules/.pnpm/@sveltejs+adapter-vercel@1.0.0-next.78/node_modules/@sveltejs/adapter-vercel/index.js:235:5)
    at async adapt (file:///Users/caleb/repos/[redacted]/node_modules/.pnpm/@sveltejs+kit@1.0.0-next.514_svelte@3.51.0+vite@3.1.7/node_modules/@sveltejs/kit/src/core/adapt/index.js:28:2)
    at async Object.handler (file:///Users/caleb/repos/[redacted]/node_modules/.pnpm/@sveltejs+kit@1.0.0-next.514_svelte@3.51.0+vite@3.1.7/node_modules/@sveltejs/kit/src/exports/vite/index.js:488:6)
    at async PluginDriver.hookParallel (file:///Users/caleb/repos/[redacted]/node_modules/.pnpm/rollup@2.78.1/node_modules/rollup/dist/es/shared/rollup.js:22632:17)
    at async Object.close (file:///Users/caleb/repos/[redacted]/node_modules/.pnpm/rollup@2.78.1/node_modules/rollup/dist/es/shared/rollup.js:23709:13)
    at async Promise.all (index 0)
ERROR Command failed with exit code 1.

System Info

System:
    OS: macOS 12.6
    CPU: (10) arm64 Apple M1 Max
    Memory: 1.45 GB / 32.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 16.17.0 - ~/.nodenv/versions/16.17.0/bin/node
    Yarn: 1.22.15 - ~/.nodenv/shims/yarn
    npm: 8.15.0 - ~/.nodenv/versions/16.17.0/bin/npm
  Browsers:
    Chrome: 106.0.5249.119
    Firefox: 105.0.3
    Safari: 16.0
  npmPackages:
    @sveltejs/adapter-netlify: ^1.0.0-next.80 => 1.0.0-next.80 
    @sveltejs/adapter-node: ^1.0.0-next.97 => 1.0.0-next.97 
    @sveltejs/adapter-vercel: ^1.0.0-next.78 => 1.0.0-next.78 
    @sveltejs/kit: ^1.0.0-next.514 => 1.0.0-next.514 
    svelte: ^3.51.0 => 3.51.0 
    vite: ^3.1.7 => 3.1.7

Severity

blocking all usage of SvelteKit

Additional Information

No response

@dummdidumm
Copy link
Member

Can you add a console.log(error.message) prior to line 318 in adapter-vercel/index.js, then run the build and paste the log right before the error? The regex match returns null and I need to know what the message is to know how to fix this.

@dummdidumm dummdidumm added pkg:adapter-vercel Pertaining to the Vercel adapter awaiting submitter labels Oct 12, 2022
@CalebBassham
Copy link
Author

Failed to resolve dependency [object Object]:
The "path" argument must be of type string. Received an instance of Object

@dummdidumm
Copy link
Member

That sounds like something inside @vercel/nft - could you add console.log(path, dep) prior to line 320 and 343 (inside the catch blocks) of @vercel/nft/out/node-file-trace.js and post the relevant log before the error happens? I'm trying to find out which package is responsible for this hickup so I can reproduce it locally - so your package.json contents probably help, too.

@CalebBassham
Copy link
Author

node-file-trace.js 320: /Users/caleb/repos/[redacted]/node_modules/.pnpm/aws-crt@1.14.5/node_modules/aws-crt/dist/native/binding.js {
  resolve: [Function (anonymous)] { [Symbol()]: true },
  normalize: [Function: mockPath] { [Symbol()]: true },
  isAbsolute: [Function: mockPath] { [Symbol()]: true },
  join: [Function: mockPath] { [Symbol()]: true },
  relative: [Function: mockPath] { [Symbol()]: true },
  toNamespacedPath: [Function: mockPath] { [Symbol()]: true },
  dirname: [Function: mockPath] { [Symbol()]: true },
  basename: [Function: mockPath] { [Symbol()]: true },
  extname: [Function: mockPath] { [Symbol()]: true },
  format: [Function: mockPath] { [Symbol()]: true },
  parse: [Function: mockPath] { [Symbol()]: true },
  sep: '/',
  delimiter: ':',
  win32: <ref *1> {
    resolve: [Function: resolve],
    normalize: [Function: normalize],
    isAbsolute: [Function: isAbsolute],
    join: [Function: join],
    relative: [Function: relative],
    toNamespacedPath: [Function: toNamespacedPath],
    dirname: [Function: dirname],
    basename: [Function: basename],
    extname: [Function: extname],
    format: [Function: bound _format],
    parse: [Function: parse],
    sep: '\\',
    delimiter: ';',
    win32: [Circular *1],
    posix: <ref *2> {
      resolve: [Function: resolve],
      normalize: [Function: normalize],
      isAbsolute: [Function: isAbsolute],
      join: [Function: join],
      relative: [Function: relative],
      toNamespacedPath: [Function: toNamespacedPath],
      dirname: [Function: dirname],
      basename: [Function: basename],
      extname: [Function: extname],
      format: [Function: bound _format],
      parse: [Function: parse],
      sep: '/',
      delimiter: ':',
      win32: [Circular *1],
      posix: [Circular *2],
      _makeLong: [Function: toNamespacedPath]
    },
    _makeLong: [Function: toNamespacedPath]
  },
  posix: <ref *2> {
    resolve: [Function: resolve],
    normalize: [Function: normalize],
    isAbsolute: [Function: isAbsolute],
    join: [Function: join],
    relative: [Function: relative],
    toNamespacedPath: [Function: toNamespacedPath],
    dirname: [Function: dirname],
    basename: [Function: basename],
    extname: [Function: extname],
    format: [Function: bound _format],
    parse: [Function: parse],
    sep: '/',
    delimiter: ':',
    win32: <ref *1> {
      resolve: [Function: resolve],
      normalize: [Function: normalize],
      isAbsolute: [Function: isAbsolute],
      join: [Function: join],
      relative: [Function: relative],
      toNamespacedPath: [Function: toNamespacedPath],
      dirname: [Function: dirname],
      basename: [Function: basename],
      extname: [Function: extname],
      format: [Function: bound _format],
      parse: [Function: parse],
      sep: '\\',
      delimiter: ';',
      win32: [Circular *1],
      posix: [Circular *2],
      _makeLong: [Function: toNamespacedPath]
    },
    posix: [Circular *2],
    _makeLong: [Function: toNamespacedPath]
  },
  _makeLong: [Function: mockPath] { [Symbol()]: true },
  default: {
    resolve: [Function (anonymous)] { [Symbol()]: true },
    normalize: [Function: mockPath] { [Symbol()]: true },
    isAbsolute: [Function: mockPath] { [Symbol()]: true },
    join: [Function: mockPath] { [Symbol()]: true },
    relative: [Function: mockPath] { [Symbol()]: true },
    toNamespacedPath: [Function: mockPath] { [Symbol()]: true },
    dirname: [Function: mockPath] { [Symbol()]: true },
    basename: [Function: mockPath] { [Symbol()]: true },
    extname: [Function: mockPath] { [Symbol()]: true },
    format: [Function: mockPath] { [Symbol()]: true },
    parse: [Function: mockPath] { [Symbol()]: true },
    sep: '/',
    delimiter: ':',
    win32: <ref *1> {
      resolve: [Function: resolve],
      normalize: [Function: normalize],
      isAbsolute: [Function: isAbsolute],
      join: [Function: join],
      relative: [Function: relative],
      toNamespacedPath: [Function: toNamespacedPath],
      dirname: [Function: dirname],
      basename: [Function: basename],
      extname: [Function: extname],
      format: [Function: bound _format],
      parse: [Function: parse],
      sep: '\\',
      delimiter: ';',
      win32: [Circular *1],
      posix: [Object],
      _makeLong: [Function: toNamespacedPath]
    },
    posix: <ref *2> {
      resolve: [Function: resolve],
      normalize: [Function: normalize],
      isAbsolute: [Function: isAbsolute],
      join: [Function: join],
      relative: [Function: relative],
      toNamespacedPath: [Function: toNamespacedPath],
      dirname: [Function: dirname],
      basename: [Function: basename],
      extname: [Function: extname],
      format: [Function: bound _format],
      parse: [Function: parse],
      sep: '/',
      delimiter: ':',
      win32: [Object],
      posix: [Circular *2],
      _makeLong: [Function: toNamespacedPath]
    },
    _makeLong: [Function: mockPath] { [Symbol()]: true }
  }
}
node-file-trace.js 320: /Users/caleb/repos/[redacted]/node_modules/.pnpm/debug@4.3.4/node_modules/debug/src/node.js supports-color

package.json:

{
  "name": "my-app",
  "version": "0.0.1",
  "engines": {
    "node": "16.x"
  },
  "scripts": {
    "dev": "vite dev",
    "build": "vite build",
    "preview": "vite preview",
    "lint": "prettier --ignore-path .gitignore --check --plugin-search-dir=. .",
    "format": "prettier --ignore-path .gitignore --write --plugin-search-dir=. ."
  },
  "devDependencies": {
    "@rollup/plugin-inject": "^4.0.4",
    "@sveltejs/adapter-netlify": "^1.0.0-next.80",
    "@sveltejs/adapter-node": "^1.0.0-next.97",
    "@sveltejs/adapter-vercel": "^1.0.0-next.78",
    "@sveltejs/kit": "^1.0.0-next.514",
    "@types/jsonwebtoken": "^8.5.9",
    "@types/lodash": "^4.14.186",
    "@types/luxon": "^3.0.1",
    "aws-sdk": "^2.1231.0",
    "prettier": "^2.7.1",
    "prettier-plugin-svelte": "^2.8.0",
    "svelte": "^3.51.0",
    "svelte-preprocess": "^4.10.7",
    "typescript": "^4.8.4",
    "vite": "^3.1.7"
  },
  "type": "module",
  "dependencies": {
    "@aws-sdk/client-s3": "^3.186.0",
    "@aws-sdk/s3-request-presigner": "^3.186.0",
    "@aws-sdk/signature-v4-crt": "^3.186.0",
    "@datadog/browser-rum": "^4.21.2",
    "@sendgrid/mail": "^7.7.0",
    "bcryptjs": "^2.4.3",
    "cookie": "^0.4.2",
    "http-status-codes": "^2.2.0",
    "jsonwebtoken": "^8.5.1",
    "lodash": "^4.17.21",
    "luxon": "^2.5.0",
    "mustache": "^4.2.0",
    "node-fetch": "^3.2.10",
    "normalize.css": "^8.0.1",
    "p-limit": "^4.0.0",
    "pluralize": "^8.0.0",
    "postgres": "^3.3.1",
    "short-unique-id": "^4.4.4"
  }
}

@dummdidumm
Copy link
Member

What happens if you adjust the code in @sveltejs/adapter-vercel/index.js like the following:

// replace line 318 with
			const result = match.exec(error.message);
			if (!result) {
				return;
			}

The build probably succeeds then, I'm wondering if this has any impact on your deployed app.

@CalebBassham
Copy link
Author

CalebBassham commented Oct 12, 2022

Sorry, had to sleep ;)

Hopefully I did that right:

if (error.message.startsWith('Failed to resolve dependency')) {
    const match = /Cannot find module '(.+?)' loaded from (.+)/;
    console.log(error.message)
    // const [, module, importer] = match.exec(error.message);
    //
    // if (!resolution_failures.has(importer)) {
    // 	resolution_failures.set(importer, []);
    // }

    const result = match.exec(error.message);
    if (!result) {
        return;
    }

    resolution_failures.get(importer).push(module);
} else {
    throw error;
}

I am getting this:

node-file-trace.js 320: /Users/caleb/repos/service-archive/node_modules/.pnpm/debug@4.3.4/node_modules/debug/src/node.js supports-color
Failed to resolve dependency [object Object]:
The "path" argument must be of type string. Received an instance of Object
Failed to resolve dependency supports-color:
Cannot find module 'supports-color' loaded from /Users/caleb/repos/service-archive/node_modules/.pnpm/debug@4.3.4/node_modules/debug/src/node.js
error during build:
ReferenceError: importer is not defined
    at file:///Users/caleb/repos/[redacted]/node_modules/.pnpm/@sveltejs+adapter-vercel@1.0.0-next.78/node_modules/@sveltejs/adapter-vercel/index.js:324:33
    at Set.forEach (<anonymous>)
    at create_function_bundle (file:///Users/caleb/repos/[redacted]/node_modules/.pnpm/@sveltejs+adapter-vercel@1.0.0-next.78/node_modules/@sveltejs/adapter-vercel/index.js:307:18)
    at async generate_serverless_function (file:///Users/caleb/repos/[redacted]/node_modules/.pnpm/@sveltejs+adapter-vercel@1.0.0-next.78/node_modules/@sveltejs/adapter-vercel/index.js:153:5)
    at async adapt (file:///Users/caleb/repos/[redacted]/node_modules/.pnpm/@sveltejs+adapter-vercel@1.0.0-next.78/node_modules/@sveltejs/adapter-vercel/index.js:235:5)
    at async adapt (file:///Users/caleb/repos/[redacted]/node_modules/.pnpm/@sveltejs+kit@1.0.0-next.514_svelte@3.51.0+vite@3.1.7/node_modules/@sveltejs/kit/src/core/adapt/index.js:28:2)
    at async Object.handler (file:///Users/caleb/repos/[redacted]/node_modules/.pnpm/@sveltejs+kit@1.0.0-next.514_svelte@3.51.0+vite@3.1.7/node_modules/@sveltejs/kit/src/exports/vite/index.js:488:6)
    at async PluginDriver.hookParallel (file:///Users/caleb/repos/[redacted]/node_modules/.pnpm/rollup@2.78.1/node_modules/rollup/dist/es/shared/rollup.js:22632:17)
    at async Object.close (file:///Users/caleb/repos/[redacted]/node_modules/.pnpm/rollup@2.78.1/node_modules/rollup/dist/es/shared/rollup.js:23709:13)
    at async Promise.all (index 0)
ERROR Command failed with exit code 1.

@dummdidumm
Copy link
Member

Sorry, I didn't paste the full code, there's one line missing at the end. It should be

if (error.message.startsWith('Failed to resolve dependency')) {
    const match = /Cannot find module '(.+?)' loaded from (.+)/;
    console.log(error.message)
    // const [, module, importer] = match.exec(error.message);
    //
    // if (!resolution_failures.has(importer)) {
    // 	resolution_failures.set(importer, []);
    // }

    const result = match.exec(error.message);
    if (!result) {
        return;
    }
    const [, module, importer] = result; // <- was missing

    resolution_failures.get(importer).push(module);
} else {
    throw error;
}

@CalebBassham
Copy link
Author

Ah that makes more sense. Here's a new one:

The "path" argument must be of type string. Received an instance of Object
Failed to resolve dependency supports-color:
Cannot find module 'supports-color' loaded from /Users/caleb/repos/[redacted]/node_modules/.pnpm/debug@4.3.4/node_modules/debug/src/node.js
error during build:
TypeError: Cannot read properties of undefined (reading 'push')
    at file:///Users/caleb/repos/[redacted]/node_modules/.pnpm/@sveltejs+adapter-vercel@1.0.0-next.78/node_modules/@sveltejs/adapter-vercel/index.js:332:46
    at Set.forEach (<anonymous>)
    at create_function_bundle (file:///Users/caleb/repos/[redacted]/node_modules/.pnpm/@sveltejs+adapter-vercel@1.0.0-next.78/node_modules/@sveltejs/adapter-vercel/index.js:307:18)
    at async generate_serverless_function (file:///Users/caleb/repos/[redacted]/node_modules/.pnpm/@sveltejs+adapter-vercel@1.0.0-next.78/node_modules/@sveltejs/adapter-vercel/index.js:153:5)
    at async adapt (file:///Users/caleb/repos/[redacted]/node_modules/.pnpm/@sveltejs+adapter-vercel@1.0.0-next.78/node_modules/@sveltejs/adapter-vercel/index.js:235:5)
    at async adapt (file:///Users/caleb/repos/[redacted]/node_modules/.pnpm/@sveltejs+kit@1.0.0-next.514_svelte@3.51.0+vite@3.1.7/node_modules/@sveltejs/kit/src/core/adapt/index.js:28:2)
    at async Object.handler (file:///Users/caleb/repos/[redacted]/node_modules/.pnpm/@sveltejs+kit@1.0.0-next.514_svelte@3.51.0+vite@3.1.7/node_modules/@sveltejs/kit/src/exports/vite/index.js:488:6)
    at async PluginDriver.hookParallel (file:///Users/caleb/repos/[redacted]/node_modules/.pnpm/rollup@2.78.1/node_modules/rollup/dist/es/shared/rollup.js:22632:17)
    at async Object.close (file:///Users/caleb/repos/[redacted]/node_modules/.pnpm/rollup@2.78.1/node_modules/rollup/dist/es/shared/rollup.js:23709:13)
    at async Promise.all (index 0)
ERROR Command failed with exit code 1.

@dummdidumm
Copy link
Member

I should have read that code snippet more closely ... 😄 This one goes through hopefully..

if (error.message.startsWith('Failed to resolve dependency')) {
    const match = /Cannot find module '(.+?)' loaded from (.+)/;
    console.log(error.message)
    // const [, module, importer] = match.exec(error.message);

    const result = match.exec(error.message);
    if (!result) {
        return;
    }
    const [, module, importer] = result;
    if (!resolution_failures.has(importer)) {
     	resolution_failures.set(importer, []);
    }

    resolution_failures.get(importer).push(module);
} else {
    throw error;
}

@CalebBassham
Copy link
Author

Ok, the build did go through with that, but I did get this at the end.

The following modules failed to locate dependencies that may (or may not) be required for your app to work:
  ../node_modules/.pnpm/debug@4.3.4/node_modules/debug/src/node.js
    - supports-color
  ✔ done

I guess I should try to deploy this, but I'll have to figure out how to deploy manually to vercel since I have just been using the GH action 🤣.

@CalebBassham
Copy link
Author

Hmmm, as far as I can tell from the docs, the only "manual" deployments are using the cli which just uploads the source code to vercel to build it. So, none of the changes to npm packages of course. Is there a simple(ish) way to temporarily swap it out?

@dummdidumm
Copy link
Member

https://www.npmjs.com/package/patch-package this should do the job

@CalebBassham
Copy link
Author

Success! What does this mean for adapter-vercel? Is this change good for everyone using the package? If so, I can create a pr with the change.

@dummdidumm
Copy link
Member

I created vercel/nft#315 first because I think that's the source of this issue

@CalebBassham
Copy link
Author

So I updated my app to use this new version without the patch. Build works, but now I get this cryptic error message.

> Using @sveltejs/adapter-vercel
  The following modules failed to locate dependencies that may (or may not) be required for your app to work:
  (unknown)
    - Failed to resolve dependency [object Object]:
The "path" argument must be of type string. Received an instance of Object

@dummdidumm
Copy link
Member

Yes, we left that in as a warning to notify people that something may not work - but if it does you can ignore it. It's a warning, not an error, so the build succeeds.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting submitter pkg:adapter-vercel Pertaining to the Vercel adapter
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants