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

"Error: Cannot find module" or "TypeError: Cannot read property 'minify' of undefined" - temporary issues from webpack and terser #113

Closed
0xi4o opened this issue Feb 3, 2019 · 8 comments

Comments

@0xi4o
Copy link

0xi4o commented Feb 3, 2019

When I run yarn start:lambda I get the following error:

yarn run v1.12.3
$ netlify-lambda serve src
netlify-lambda: Starting server
Lambda server is listening on 9000
module.js:549
    throw err;
    ^

Error: Cannot find module '/home/ilangorajagopal/Projects/dotconfig/functions/lambda/generate'
    at Function.Module._resolveFilename (module.js:547:15)
    at Function.resolve (internal/module.js:18:19)
    at Object.clearCache (/home/ilangorajagopal/Projects/dotconfig/functions/node_modules/netlify-lambda/lib/serve.js:130:36)
    at /home/ilangorajagopal/Projects/dotconfig/functions/node_modules/netlify-lambda/bin/cmd.js:38:16
    at Array.forEach (<anonymous>)
    at Watching.handler (/home/ilangorajagopal/Projects/dotconfig/functions/node_modules/netlify-lambda/bin/cmd.js:37:32)
    at compiler.hooks.done.callAsync (/home/ilangorajagopal/Projects/dotconfig/functions/node_modules/webpack/lib/Watching.js:98:9)
    at AsyncSeriesHook.eval [as callAsync] (eval at create (/home/ilangorajagopal/Projects/dotconfig/functions/node_modules/tapable/lib/HookCodeFactory.js:32:10), <anonymous>:6:1)
    at AsyncSeriesHook.lazyCompileHook (/home/ilangorajagopal/Projects/dotconfig/functions/node_modules/tapable/lib/Hook.js:154:20)
    at Watching._done (/home/ilangorajagopal/Projects/dotconfig/functions/node_modules/webpack/lib/Watching.js:97:28)
    at onCompiled (/home/ilangorajagopal/Projects/dotconfig/functions/node_modules/webpack/lib/Watching.js:47:18)
    at hooks.afterCompile.callAsync.err (/home/ilangorajagopal/Projects/dotconfig/functions/node_modules/webpack/lib/Compiler.js:630:14)
    at AsyncSeriesHook.eval [as callAsync] (eval at create (/home/ilangorajagopal/Projects/dotconfig/functions/node_modules/tapable/lib/HookCodeFactory.js:32:10), <anonymous>:6:1)
    at AsyncSeriesHook.lazyCompileHook (/home/ilangorajagopal/Projects/dotconfig/functions/node_modules/tapable/lib/Hook.js:154:20)
    at compilation.seal.err (/home/ilangorajagopal/Projects/dotconfig/functions/node_modules/webpack/lib/Compiler.js:627:30)
    at AsyncSeriesHook.eval [as callAsync] (eval at create (/home/ilangorajagopal/Projects/dotconfig/functions/node_modules/tapable/lib/HookCodeFactory.js:32:10), <anonymous>:6:1)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Seeing a previous similar issue, I tried to build it first to see if that would run serve properly. But I get this error when I run yarn build:lambda:

yarn run v1.12.3
yarn run v1.12.3
$ netlify-lambda build src
netlify-lambda: Building functions
Hash: 7158f52f423c80f8443f
Version: webpack 4.29.0
Time: 400ms
Built at: 2019-02-03 09:50:24
      Asset      Size  Chunks  Chunk Names
generate.js  3.76 KiB       0  generate
Entrypoint generate = generate.js
[0] ./generate.js 128 bytes {0} [built]

ERROR in generate.js from Terser
TypeError: Cannot read property 'minify' of undefined
    at minify (/home/ilangorajagopal/Projects/dotconfig/functions/node_modules/terser-webpack-plugin/dist/minify.js:175:23)
    at module.exports (/home/ilangorajagopal/Projects/dotconfig/functions/node_modules/terser-webpack-plugin/dist/worker.js:13:40)
    at handle (/home/ilangorajagopal/Projects/dotconfig/functions/node_modules/worker-farm/lib/child/index.js:44:8)
    at process.<anonymous> (/home/ilangorajagopal/Projects/dotconfig/functions/node_modules/worker-farm/lib/child/index.js:51:3)
    at emitTwo (events.js:126:13)
    at process.emit (events.js:214:7)
    at emit (internal/child_process.js:772:12)
    at _combinedTickCallback (internal/process/next_tick.js:141:11)
    at process._tickCallback (internal/process/next_tick.js:180:9)
Done in 2.02s.

Here is my package.json:

{
  "name": "functions",
  "version": "0.1.0",
  "description": "",
  "private": true,
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start:lambda": "netlify-lambda serve src",
    "build:lambda": "netlify-lambda build src"
  },
  "keywords": [],
  "author": "Ilango Rajagopal",
  "license": "ISC",
  "devDependencies": {
    "netlify-lambda": "^1.3.1"
  }
}

netlify.toml:

[build]
  command = "yarn build:lambda"
  functions = "lambda" #  netlify-lambda reads this

src/generate.js

exports.handler = function(event, context, callback) {
	// your server-side functionality
	console.log('Hello, Netlify!');
};

I'm running Node 8.10.0. When I was first testing Netlify functions last week with a similar set of files, it worked perfectly. Unfortunately I no longer have that code.

@danew
Copy link

danew commented Feb 3, 2019

I had a similar issue with the build step.

As a temporary fix disabling the minimizing of the functions works. Here's how to do that Webpack Configuration.

It seems that other people are also having similar issues with the serve script too, see Issue #111

@swyxio
Copy link
Contributor

swyxio commented Feb 3, 2019

hmm. making a small sample repo to try to reproduce. thanks for filing

EDIT: I can reproduce, and this is broken since v1.0.0 (v0.4.0 works). investigating

@swyxio
Copy link
Contributor

swyxio commented Feb 3, 2019

based on how recent all these reports are coming up, this seems to be a bug in the terser API: vuejs/vue-cli#3407 (comment)

@swyxio
Copy link
Contributor

swyxio commented Feb 3, 2019

confirmed. pls wait for them to resolve, or pin the resolution of terser for now: terser/terser#251

@0xi4o
Copy link
Author

0xi4o commented Feb 3, 2019

Thank you for replying so soon! My side project was held up because I couldn't find a solution to this.

The terser update was pushed only a few hours ago. Building with [email protected] works. And I can now confirm that serve works with [email protected].

@swyxio
Copy link
Contributor

swyxio commented Feb 3, 2019

yes because it uses an older webpack version. anyway, i think i'm gonna close this as its a upstream issue that should be fixed soon (angular, vue, react are all affected lol so we have company). cheers

@swyxio swyxio closed this as completed Feb 3, 2019
@swyxio swyxio pinned this issue Feb 3, 2019
@swyxio swyxio changed the title Unable to serve or build due to different errors "Error: Cannot find module" or "TypeError: Cannot read property 'minify' of undefined" - temporary issues from webpack and terser Feb 3, 2019
@swyxio swyxio changed the title "Error: Cannot find module" or "TypeError: Cannot read property 'minify' of undefined" - temporary issues from webpack and terser PLEASE READ (Feb 2nd) "Error: Cannot find module" or "TypeError: Cannot read property 'minify' of undefined" - temporary issues from webpack and terser Feb 3, 2019
@swyxio swyxio unpinned this issue Feb 13, 2019
@swyxio
Copy link
Contributor

swyxio commented Feb 13, 2019

i think this has been resolved, ping me if not

@0xi4o
Copy link
Author

0xi4o commented Feb 13, 2019

@sw-yx Yes! Both serve and build works with latest version. Thanks.

@swyxio swyxio changed the title PLEASE READ (Feb 2nd) "Error: Cannot find module" or "TypeError: Cannot read property 'minify' of undefined" - temporary issues from webpack and terser "Error: Cannot find module" or "TypeError: Cannot read property 'minify' of undefined" - temporary issues from webpack and terser Feb 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants