netlify-lambda: [BUG] Babel-loader - hidden dependency

after running command ./node_modules/.bin/netlify-lambda build functions-source/ I god

netlify-lambda: Building functions
Hash: 2f36233598c9262552e4
Version: webpack 4.20.2
Time: 1142ms
Built at: 2018-10-16 12:47:52
    Asset      Size  Chunks  Chunk Names
rating.js  1.21 KiB       0  rating
Entrypoint rating = rating.js
[0] ./rating.js 254 bytes {0} [built] [failed] [1 error]

ERROR in ./rating.js
Module build failed (from ../node_modules/babel-loader/lib/index.js):
TypeError: Cannot read property 'babel' of undefined
    at Object.module.exports (/Users/nikolay/Projects/autokwix/node_modules/babel-loader/lib/index.js:103:36)

after installing babel-loader - it started to work

how on earth?

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 22 (8 by maintainers)

Most upvoted comments

I have been getting this same issue on a new create-react-app and was wondering why it wasn’t working until finally doing a yarn add -D babel-loader and starting the netlify-lambda serve command all over again to which it works.

My conclusion is that it might have to do with react-scripts: 2.x.x.

My error was more along the lines of: ERROR in Entry module not found: Error: Can't resolve 'babel-loader' in '/Users/[redacted]/Desktop/test/src/functions'

Update: I figured it out. To anyone out there using react-static (older versions ~before v6.x.x) with netlify-lambda (v0.4.0), I needed to upgrade both my versions of react-static(now v7.x.x) and netlify lambda(now v1.4.5).


Hi @sw-yx I had lambda ^0.4.0 and it started to fail all of a sudden, without touching any config nor the functions and experienced this during build:

11:59:35 PM: failed during stage 'preparing functions for deployment': exit status 1
11:59:34 PM: Error: Cannot find module './dist/react-hot-loader.production.min.js' from '/opt/build/repo/dist/lambda'
11:59:34 PM: Failing build: Failed to prepare functions for deployment

I upgraded to netlify-lambda: ^1.4.5 and yarn added -D babel-loader: ^8.0.5 but the build functions failed and it seems to have something to do with babel-loader 😦

2:55:11 PM: netlify-lambda: Building functions
2:55:12 PM: Hash: 101544bdec7f89cd2c64
2:55:12 PM: Version: webpack 4.30.0
2:55:12 PM: Time: 456ms
2:55:12 PM: Built at: 2019-04-28 06:55:12
2:55:12 PM:        Asset      Size  Chunks  Chunk Names
2:55:12 PM: recaptcha.js  3.04 KiB       0  recaptcha
2:55:12 PM: Entrypoint recaptcha = recaptcha.js
2:55:12 PM: [0] ./recaptcha.js 2.08 KiB {0} [built] [failed] [1 error]
2:55:12 PM: ERROR in ./recaptcha.js
2:55:12 PM: Module build failed (from ../node_modules/babel-loader/lib/index.js):
2:55:12 PM: Error: Plugin/Preset files are not allowed to export objects, only functions. In /opt/build/repo/node_modules/react-static/babel-preset.js

@sw-yx Seems as if it’s a mixed bag.

Ex. I’ll get the ERROR in Entry module not found: Error: Can't resolve 'babel-loader' in '/Users/[redacted]/Desktop/test/src/functions' from a clean install but when I install the babel loader I get:

yarn run v1.13.0-20181004.1524
$ netlify-lambda serve src/lambda
netlify-lambda: Starting server
Lambda server is listening on 9000
Unhandled rejection Error: Cannot find module '/Users/[redacted]/Desktop/test/lambda/hello'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:581:15)
    at Function.resolve (internal/modules/cjs/helpers.js:30:19)
    at Object.clearCache (/Users/[redacted]/Desktop/test/node_modules/netlify-lambda/lib/serve.js:111:36)
    at /Users/[redacted]/Desktop/test/node_modules/netlify-lambda/bin/cmd.js:38:16
    at Array.forEach (<anonymous>)
    at Watching.handler (/Users/[redacted]/Desktop/test/node_modules/netlify-lambda/bin/cmd.js:37:32)
    at compiler.hooks.done.callAsync (/Users/[redacted]/Desktop/test/node_modules/netlify-lambda/node_modules/webpack/lib/Watching.js:98:9)
    at AsyncSeriesHook.eval [as callAsync] (eval at create (/Users/[redacted]/Desktop/test/node_modules/tapable/lib/HookCodeFactory.js:32:10), <anonymous>:6:1)
    at AsyncSeriesHook.lazyCompileHook (/Users/[redacted]/Desktop/test/node_modules/tapable/lib/Hook.js:154:20)
    at Watching._done (/Users/[redacted]/Desktop/test/node_modules/netlify-lambda/node_modules/webpack/lib/Watching.js:97:28)
    at onCompiled (/Users/[redacted]/Desktop/test/node_modules/netlify-lambda/node_modules/webpack/lib/Watching.js:47:18)
    at hooks.afterCompile.callAsync.err (/Users/[redacted]/Desktop/test/node_modules/netlify-lambda/node_modules/webpack/lib/Compiler.js:552:14)
    at AsyncSeriesHook.eval [as callAsync] (eval at create (/Users/[redacted]/Desktop/test/node_modules/tapable/lib/HookCodeFactory.js:32:10), <anonymous>:6:1)
    at AsyncSeriesHook.lazyCompileHook (/Users/[redacted]/Desktop/test/node_modules/tapable/lib/Hook.js:154:20)
    at compilation.seal.err (/Users/[redacted]/Desktop/test/node_modules/netlify-lambda/node_modules/webpack/lib/Compiler.js:549:30)
    at AsyncSeriesHook.eval [as callAsync] (eval at create (/Users/[redacted]/Desktop/test/node_modules/tapable/lib/HookCodeFactory.js:32:10), <anonymous>:6:1)

which leads me to believe it has to do with version mismatch as from what I’ve gathered netlify-lambda brings its own version of babel-loader.

If I delete the yarn.lock file and node_module then redo a yarn to reinstall everything and run the netlify-lambda serve src/lambda it begins to work.

Im not as familiar with babel but I’ll see what can be done to get it from messing up like so.

Another thing I’ve noticed is using Yarn Plug and Play it gives the same error with no babel-loader and no matter what I do it will not work at all even if I try installing it.