Hi
My site name is stupefied-lamarr-20c8d9
On the server side of my app I have lambda functions and within those I’m using apollo-server-lambda and mongodb and am trying to upgrade both to a new major version
when I do that, on my local machine it builds, but when it starts to run I get a series of errors like this
ERROR in ../node_modules/@graphql-tools/mock/index.mjs 782:9-19
[1] Can't import the named export 'MapperKind' from non EcmaScript module (only default export is available)
Googling it, I found that the issue is that webpack is not handling .mjs files properly, so adding this to webpack.config.js was the fix:
module: {
rules: [
{
test: /\.mjs$/,
include: /node_modules/,
type: 'javascript/auto'
}
]
},
(There was more than one place I found this same answer, here is one example:
node.js - Can't import the named export XXXX from non EcmaScript module (only default export is available) - Stack Overflow)
My package.json file has a script like this
"scripts": {
...
"build:lambda": "netlify-lambda build lambdaFunctions --config ./webpack.config.js",
}
Note that
- “build:lambda” is in turn being called by another script, to build and run my local dev environment
- lambdaFunctions is the folder where I have the source code for the lambda functions that are getting built (I think usually this is called just “lambda”)
My problem is that after adding the above code to webpack.config.js, it seems to have no effect
So my next thought was that I need to understand how the netlify-lambda build function uses webpack and that webpack.config.js file…can someone give me some pointers on that? Or if anyone is familiar with this issue and has specific advice, that’d be even better.
Thanks!
Simon
Here’s the full build log (this is just running locally):
> parent@1.0.0 dev
> cd ./serverLambda && npm run build:lambda && cd .. && npm run tailwind:css && concurrently "npm run client" "npm run lambda"
> server-lambda@1.0.0 build:lambda
> netlify-lambda build lambdaFunctions --config ./webpack.config.js
netlify-lambda: Building functions
reading the webpack.config.js file
Hash: 441f43cefd6fe09ebf40
Version: webpack 4.44.1
Time: 1673ms
Built at: 02/28/2022 8:25:53 AM
Asset Size Chunks Chunk Names
auth.js 36 KiB auth [emitted] auth
authReturn.js 33.9 KiB authReturn [emitted] authReturn
authReturnGoogle.js 33 KiB authReturnGoogle [emitted] authReturnGoogle
dbConnector.js 9.71 KiB dbConnector [emitted] dbConnector
graphql.js 67.8 KiB graphql [emitted] graphql
resolvers.js 50.3 KiB resolvers [emitted] resolvers
Entrypoint auth = auth.js
Entrypoint authReturn = authReturn.js
Entrypoint authReturnGoogle = authReturnGoogle.js
Entrypoint dbConnector = dbConnector.js
Entrypoint graphql = graphql.js
Entrypoint resolvers = resolvers.js
[../config/keys.js] 190 bytes {auth} {authReturn} {authReturnGoogle} {dbConnector} {graphql} {resolvers} [built]
[../constants.js] 406 bytes {auth} {authReturn} {authReturnGoogle} {dbConnector} {graphql} {resolvers} [built]
[./auth.js] 1.83 KiB {auth} [built]
[./authReturn.js] 2.42 KiB {authReturn} [built]
[./authReturnGoogle.js] 2.85 KiB {authReturnGoogle} [built]
[./dbConnector.js] 1.1 KiB {dbConnector} {auth} {authReturn} {authReturnGoogle} {graphql} [built]
[./graphql.js] 2.46 KiB {graphql} [built]
[./helpers/authHelpers.js] 2.33 KiB {auth} {authReturn} {authReturnGoogle} [built]
[./helpers/facebookAuthHelpers.js] 3.69 KiB {auth} {authReturn} [built]
[./helpers/googleAuthHelpers.js] 2.15 KiB {auth} {authReturnGoogle} [built]
[./helpers/graphqlHelpers.js] 4.51 KiB {graphql} [built]
[./helpers/index.js] 1.93 KiB {auth} {authReturn} {authReturnGoogle} {graphql} {resolvers} [built]
[./helpers/logger.js] 677 bytes {auth} {authReturn} {authReturnGoogle} {dbConnector} {graphql} {resolvers} [built]
[./helpers/sheetHelpers.js] 6.93 KiB {graphql} {resolvers} [built]
[./resolvers.js] 11.2 KiB {resolvers} {graphql} [built]
+ 24 hidden modules
> parent@1.0.0 tailwind:css
> tailwind build client/src/css/tailwind.src.css -c client/tailwind.config.js -o client/src/css/tailwind.css
[deprecation] Running tailwindcss without -i, please provide an input file.
Done in 876ms.
[1]
[1] > parent@1.0.0 lambda
[1] > npm run lambda --prefix serverLambda
[1]
[0]
[0] > parent@1.0.0 client
[0] > npm run start --prefix client
[0]
[0]
[0] > client@0.1.0 start
[0] > react-scripts start
[0]
[1]
[1] > server-lambda@1.0.0 lambda
[1] > netlify-lambda serve lambdaFunctions
[1]
[1] netlify-lambda: Starting server
[0] [HPM] Proxy created: /.netlify/functions/,/.netlify/functions/auth,/.netlify/functions/authReturn -> http://localhost:9000
[0] [HPM] Proxy rewrite rule created: "^/\.netlify/functions" ~> ""
[0] (node:2596) [DEP_WEBPACK_DEV_SERVER_ON_AFTER_SETUP_MIDDLEWARE] DeprecationWarning: 'onAfterSetupMiddleware' option is deprecated. Please use the 'setupMiddlewares' option.
[0] (Use `node --trace-deprecation ...` to show where the warning was created)
[0] (node:2596) [DEP_WEBPACK_DEV_SERVER_ON_BEFORE_SETUP_MIDDLEWARE] DeprecationWarning: 'onBeforeSetupMiddleware' option is deprecated. Please use the 'setupMiddlewares' option.
[0] Starting the development server...
[0]
[0] Compiled successfully!
[0]
[0] You can now view client in the browser.
[0]
[0] Local: http://localhost:3000
[0] On Your Network: http://10.0.0.17:3000
[0]
[0] Note that the development build is not optimized.
[0] To create a production build, use npm run build.
[0]
[0] asset static/js/bundle.js 4.02 MiB [emitted] (name: main) 1 related asset
[0] asset index.html 1.17 KiB [emitted]
[0] asset asset-manifest.json 190 bytes [emitted]
[0] cached modules 3.38 MiB (javascript) 28.1 KiB (runtime) [cached] 900 modules
[0] webpack 5.66.0 compiled successfully in 6032 ms
[0] [HPM] Error occurred while proxying request localhost:3000/graphql to http://localhost:9000/ [ECONNREFUSED] (https://nodejs.org/api/errors.html#errors_common_system_errors)
[1] Hash: 64f7d85a9a8623b78716
[1] Version: webpack 4.44.1
[1] Time: 13414ms
[1] Built at: 02/28/2022 8:26:15 AM
[1] Asset Size Chunks Chunk Names
[1] auth.js 19.1 MiB auth [emitted] auth
[1] authReturn.js 4.8 MiB authReturn [emitted] authReturn
[1] authReturnGoogle.js 19.1 MiB authReturnGoogle [emitted] authReturnGoogle
[1] dbConnector.js 4.69 MiB dbConnector [emitted] dbConnector
[1] graphql.js 8.45 MiB graphql [emitted] graphql
[1] resolvers.js 8.43 MiB resolvers [emitted] resolvers
[1] Entrypoint auth = auth.js
[1] Entrypoint authReturn = authReturn.js
[1] Entrypoint authReturnGoogle = authReturnGoogle.js
[1] Entrypoint dbConnector = dbConnector.js
[1] Entrypoint graphql = graphql.js
[1] Entrypoint resolvers = resolvers.js
[1] [../config/keys.js] 190 bytes {auth} {authReturn} {authReturnGoogle} {dbConnector} {graphql} {resolvers} [built]
[1] [../constants.js] 406 bytes {auth} {authReturn} {authReturnGoogle} {dbConnector} {graphql} {resolvers} [built]
[1] [../node_modules/apollo-server-lambda/dist/index.js] 1.6 KiB {graphql} {resolvers} [built]
[1] [../node_modules/googleapis/build/src/index.js] 57.4 KiB {auth} {authReturnGoogle} [built]
[1] [../node_modules/mongoose/index.js] 186 bytes {auth} {authReturn} {authReturnGoogle} {dbConnector} {graphql} {resolvers} [built]
[1] [../node_modules/ramda/es/index.js] 12.9 KiB {auth} {authReturn} {authReturnGoogle} {dbConnector} {graphql} {resolvers} [built]
[1] [./auth.js] 1.83 KiB {auth} [built]
[1] [./authReturn.js] 2.42 KiB {authReturn} [built]
[1] [./authReturnGoogle.js] 2.85 KiB {authReturnGoogle} [built]
[1] [./dbConnector.js] 1.1 KiB {dbConnector} {auth} {authReturn} {authReturnGoogle} {graphql} [built]
[1] [./graphql.js] 2.46 KiB {graphql} [built]
[1] [./helpers/authHelpers.js] 2.33 KiB {auth} {authReturn} {authReturnGoogle} [built]
[1] [./helpers/facebookAuthHelpers.js] 3.69 KiB {auth} {authReturn} [built]
[1] [./helpers/googleAuthHelpers.js] 2.15 KiB {auth} {authReturnGoogle} [built]
[1] [./resolvers.js] 11.2 KiB {resolvers} {graphql} [built]
[1] + 1964 hidden modules
[1]
[1] WARNING in ../node_modules/express/lib/view.js 81:13-25
[1] Critical dependency: the request of a dependency is an expression
[1] @ ../node_modules/express/lib/application.js
[1] @ ../node_modules/express/lib/express.js
[1] @ ../node_modules/express/index.js
[1] @ ../node_modules/apollo-server-lambda/dist/ApolloServer.js
[1] @ ../node_modules/apollo-server-lambda/dist/index.js
[1] @ ./resolvers.js
[1]
[1] WARNING in ../node_modules/mongodb/lib/deps.js
[1] Module not found: Error: Can't resolve 'snappy' in 'C:\Simon\code\deepsheet\serverLambda\node_modules\mongodb\lib'
[1] @ ../node_modules/mongodb/lib/deps.js
[1] @ ../node_modules/mongodb/lib/index.js
[1] @ ../node_modules/mongodb-client-encryption/lib/index.js
[1] @ ../node_modules/mongoose/node_modules/mongodb/lib/encrypter.js
[1] @ ../node_modules/mongoose/node_modules/mongodb/lib/connection_string.js
[1] @ ../node_modules/mongoose/node_modules/mongodb/lib/mongo_client.js
[1] @ ../node_modules/mongoose/node_modules/mongodb/lib/index.js
[1] @ ../node_modules/mongoose/lib/index.js
[1] @ ../node_modules/mongoose/index.js
[1] @ ./dbConnector.js
[1]
[1] WARNING in ../node_modules/mongoose/node_modules/mongodb/lib/deps.js
[1] Module not found: Error: Can't resolve 'snappy' in 'C:\Simon\code\deepsheet\serverLambda\node_modules\mongoose\node_modules\mongodb\lib'
[1] @ ../node_modules/mongoose/node_modules/mongodb/lib/deps.js
[1] @ ../node_modules/mongoose/node_modules/mongodb/lib/index.js
[1] @ ../node_modules/mongoose/lib/index.js
[1] @ ../node_modules/mongoose/index.js
[1] @ ./dbConnector.js
[1]
[1] WARNING in ../node_modules/mongodb/lib/deps.js
[1] Module not found: Error: Can't resolve 'snappy/package.json' in 'C:\Simon\code\deepsheet\serverLambda\node_modules\mongodb\lib'
[1] @ ../node_modules/mongodb/lib/deps.js
[1] @ ../node_modules/mongodb/lib/index.js
[1] @ ../node_modules/mongodb-client-encryption/lib/index.js
[1] @ ../node_modules/mongoose/node_modules/mongodb/lib/encrypter.js
[1] @ ../node_modules/mongoose/node_modules/mongodb/lib/connection_string.js
[1] @ ../node_modules/mongoose/node_modules/mongodb/lib/mongo_client.js
[1] @ ../node_modules/mongoose/node_modules/mongodb/lib/index.js
[1] @ ../node_modules/mongoose/lib/index.js
[1] @ ../node_modules/mongoose/index.js
[1] @ ./dbConnector.js
[1]
[1] WARNING in ../node_modules/mongoose/node_modules/mongodb/lib/deps.js
[1] Module not found: Error: Can't resolve 'snappy/package.json' in 'C:\Simon\code\deepsheet\serverLambda\node_modules\mongoose\node_modules\mongodb\lib'
[1] @ ../node_modules/mongoose/node_modules/mongodb/lib/deps.js
[1] @ ../node_modules/mongoose/node_modules/mongodb/lib/index.js
[1] @ ../node_modules/mongoose/lib/index.js
[1] @ ../node_modules/mongoose/index.js
[1] @ ./dbConnector.js
[1]
[1] ERROR in ../node_modules/@graphql-tools/mock/index.mjs 733:9-19
[1] Can't import the named export 'MapperKind' from non EcmaScript module (only default export is available)
[1] @ ../node_modules/apollo-server-core/dist/ApolloServer.js
[1] @ ../node_modules/apollo-server-core/dist/index.js
[1] @ ../node_modules/apollo-server-lambda/dist/index.js
[1] @ ./resolvers.js
[1]
[1] ERROR in ../node_modules/@graphql-tools/mock/index.mjs 782:9-19
[1] Can't import the named export 'MapperKind' from non EcmaScript module (only default export is available)
[1] @ ../node_modules/apollo-server-core/dist/ApolloServer.js
[1] @ ../node_modules/apollo-server-core/dist/index.js
[1] @ ../node_modules/apollo-server-lambda/dist/index.js
[1] @ ./resolvers.js
[1]
[1] ERROR in ../node_modules/@graphql-tools/schema/index.mjs 59:9-19
[1] Can't import the named export 'MapperKind' from non EcmaScript module (only default export is available)
[1] @ ../node_modules/apollo-server-core/dist/ApolloServer.js
[1] @ ../node_modules/apollo-server-core/dist/index.js
[1] @ ../node_modules/apollo-server-lambda/dist/index.js
[1] @ ./resolvers.js
[1]
[1] ERROR in ../node_modules/@graphql-tools/schema/index.mjs 299:9-19
[1] Can't import the named export 'MapperKind' from non EcmaScript module (only default export is available)
[1] @ ../node_modules/apollo-server-core/dist/ApolloServer.js
[1] @ ../node_modules/apollo-server-core/dist/index.js
[1] @ ../node_modules/apollo-server-lambda/dist/index.js
[1] @ ./resolvers.js
[1]
… many other similar errors here…
[1] Lambda server is listening on 9000