serverless-nextjs / serverless-next.js

⚡ Deploy your Next.js apps on AWS Lambda@Edge via Serverless Components
MIT License
4.47k stars 457 forks source link

webpack/runtime/compat The "path" argument must be of type string. Received undefined with new Worker(new URL(...)) and worker import(s) #2220

Open talaikis opened 2 years ago

talaikis commented 2 years ago

Issue Summary

webpack/runtime/compat The "path" argument must be of type string. Received undefined with new Worker(new URL(...)) and comlink

Actual behavior

webpack/runtime/compat The "path" argument must be of type string

Expected behavior

Probably should work, because nextjs build worksfine.

Steps to reproduce

Repo: https://github.com/talaikis/next-worker-comlink-repro

on deployment gives Error:

warn  - No ESLint configuration detected. Run next lint to begin setup
Failed to compile.

webpack/runtime/compat
The "path" argument must be of type string. Received undefined

> Build failed because of webpack errors
info  - Checking validity of types...
info  - Creating an optimized production build...
    at makeError (C:\Users\DXenu\.serverless\components\registry\npm\@sls-next\serverless-component@3.6.0\node_modules\@sls-next\serverless-component\node_modules\execa\lib\error.js:60:11)
    at handlePromise (C:\Users\DXenu\.serverless\components\registry\npm\@sls-next\serverless-component@3.6.0\node_modules\@sls-next\serverless-component\node_modules\execa\index.js:118:26)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at async Builder.build (C:\Users\DXenu\.serverless\components\registry\npm\@sls-next\serverless-component@3.6.0\node_modules\@sls-next\serverless-component\node_modules\@sls-next\lambda-at-edge\dist\build.js:377:13)
    at async NextjsComponent.build (C:\Users\DXenu\.serverless\components\registry\npm\@sls-next\serverless-component@3.6.0\node_modules\@sls-next\serverless-component\dist\component.js:165:13)
    at async NextjsComponent.default (C:\Users\DXenu\.serverless\components\registry\npm\@sls-next\serverless-component@3.6.0\node_modules\@sls-next\serverless-component\dist\component.js:22:13)
    at async fn (\with-next-worker-repro\node_modules\@serverless\template\utils.js:280:41)
    at async Promise.all (index 0)
    at async executeGraph (\with-next-worker-repro\node_modules\@serverless\template\utils.js:294:3)
    at async Template.default (\with-next-worker-repro\node_modules\@serverless\template\serverless.js:67:38) {
  shortMessage: 'Command failed with exit code 1: node_modules/.bin/next build',
  command: 'node_modules/.bin/next build',
  escapedCommand: '"node_modules/.bin/next" build',
  exitCode: 1,
  signal: undefined,
  signalDescription: undefined,
  stdout: 'info  - Checking validity of types...\n' +
    'info  - Creating an optimized production build...',
  stderr: 'warn  - The `target` config is deprecated and will be removed in a future version.\n' +
    'See more info here https://nextjs.org/docs/messages/deprecated-target-config\n' +
    'warn  - No ESLint configuration detected. Run next lint to begin setup\n' +
    'Failed to compile.\n' +
    '\n' +
    'webpack/runtime/compat\n' +
    'The "path" argument must be of type string. Received undefined\n' +
    '\n' +
    '\n' +
    '> Build failed because of webpack errors',
  failed: true,
  timedOut: false,
  isCanceled: false,
  killed: false
}

Versions

Checklist

manmal commented 2 years ago

I got this error when importing (or requiring) a relative path in a file that the web worker imports.

The following workaround worked for me:

const properties = require(path.join(process.cwd(), `data/file.json`));

instead of

const properties = require(`../data/file.json`));
talaikis commented 2 years ago

Well, without any relative imports, it does not work with imported packages.