-
Notifications
You must be signed in to change notification settings - Fork 417
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
V3: Unable to import module 'handler': Error #43
Comments
I'm having the same issue. I can run the function locally with
|
I have the same problem as well. Able to run locally, but fails when deployed.
Anyone know how to fix? |
Hmm, it's always |
In my case, making sure that ALL required modules were actually in package.json solved the issue :) |
yeah that error report doesn't help much. I'm closing this hoping that the last @msl-kabo messages fixes it for everyone. |
I just ran into this issue again, and it was caused by a dependency accidentally being added to |
I had this issue until I discovered I was missing "babel-runtime"in |
I am having the same problem. const path = require('path');
my package.json:
Webpack also shows this message in console: I intentionally put aws-sdk in devDependencies because it's already available on AWS. There is no node_modules in the deployment zip. |
@dimitrovs Can you try with the V3 RC? You can use it with |
@HyperBrain you can see in my package.json that I am using the RC. Serverless.yml:
|
If webpack only shows the two externals:
aws-sdk is a dev dependency and thus will not be packaged, but Can you provide a sample project (on GitHub or Gist) with the minimal contents with that the issue is reproducible? BTW: Which Node version do you use to build and deploy? Additionally you can invoke serverless with the |
You are right, I checked my code and the only external dependency I am currently using is request, I removed the other ones from package.json now. My Node version is v6.11.0 . I copied all the config from serverless-offline and it works now, you can close the issue I guess. I think the problem was solved by adding:
to serverless.yml and:
to webpack.config.js and:
to package.json dependencies and:
to devDependencies . |
Glad to here that it works now 😃 . Indeed setting Maybe the default should be |
For anyone who casually skims the responses (like I did), the quick solution is to make sure everything you require is in your package.json under "dependencies". If you are still getting errors, check out dimitrovs' issue. |
Also, I updated my answer as I just realized "babel-polyfill" belongs in |
I have the following dependencies: "devDependencies": {
"babel-core": "6.26.0",
"babel-loader": "7.1.2",
"babel-plugin-source-map-support": "2.0.0",
"babel-plugin-transform-runtime": "6.23.0",
"babel-preset-env": "1.6.1",
"babel-preset-stage-3": "6.24.1",
"serverless-webpack": "4.3.0",
"webpack": "3.11.0",
"webpack-node-externals": "1.6.0"
},
"dependencies": {
"@awspilot/dynamodb": "1.0.9",
"aws-sdk": "2.194.0",
"babel-runtime": "6.26.0",
"jest": "22.3.0",
"moment": "2.20.1",
"serverless-domain-manager": "2.3.0",
"source-map-support": "0.5.3",
"uuid": "3.2.1",
"uuid-validate": "0.0.2"
} I moved babel-runtime, jest, serverless-domain-manager and source-map-support to How can we figure out what should be in dependencies and what should be in devDependencies ? |
@Vadorequest I agree that a better message should be provided. Maybe the plugin could error out if a required dependency is detected that appears in devDependencies. regarding your deps - babel-runtime and source-map-support are dependencies that are used at runtime and not build time, so they must be in the dependencies section. For domain-manager, I don't know if there are any runtime function in there. |
Eventually, only babel-runtime and source-map-support were needed in this case, but I had to go to the repo to make sure of that. |
Well the problem is webpack 4.1.0 version. I updated all the packages first that also updated webpack to latest version. Back to webpack 3.11.0 and its solved. Maybe you should emphasise this more on the documentation @HyperBrain |
@Can-Sahin If you want to see what versions I use, take a look at https://github.com/Vadorequest/serverless-with-next (updated yesterday) Since I only use specific version I avoid running into this kind of issues. |
@Can-Sahin @Vadorequest There is a preview version of the webpack plugin available that supports webpack 4 (see #331). You can try |
@dimitrovs's solution of adding the following option worked for me.
Using
|
For reference, I experienced this issue because I used I added |
I was on a Mac, and my exports were case insensitive, so the local invoke worked. Easy to overlook! |
Hi @HyperBrain, I am running into this issue as well with a typescript app. I have created a complete repo here for reference. I can access and use the app locally via
which seems consistent with the experiences of the folks above. In order to try and debug in production myself I simply moved all the modules from Any help or insight would be greatly appreciated. Kind regards, Luke |
@lukebyrne could you try changing this file's export from |
@hassankhan Thanks for the prompt response, I tried your suggestion but to no avail. Error still the same via the logs:
|
@hassankhan Feels like this issue could be a pretty biggish one for users of Really appreciate your assistance so far. |
@hassankhan I updated the repo https://github.com/lukebyrne/typescript-express-jwt-lambda to reflect your suggestions |
I was having similar issues, noticed in your repo you're using yarn. i resolved my problem with
in my serverless.yml Apparently it was by default getting set to npm and causing some problems. not sure why that would be the issue, but figured I'd throw it out there to see if it helps! |
@adamwilbert Updated in the repo but no luck. Do you think you could pull down the repo and see what happens when you deploy it? |
I think it might an issue with knex in my webpack.config.js https://github.com/lukebyrne/typescript-express-jwt-lambda/blob/master/webpack.config.js I was googling around saw on a few Github issues that you have had similar issues with knex, any suggestions? I am thinking that my sls deploy is not packaging up knex correctly and hence why its falling over on production. |
@adamwilbert @hassankhan I seem to have fixed the issue I was having with webpack but modifying my webpack.config.js Made the change of:
as well as
You can see the Lambda working here: https://kirhd1mpkb.execute-api.us-west-2.amazonaws.com/production/ Just having other issues now with API timeouts when registering or logging in a user. Will work on them next. |
Glad you finally got it working in the end @lukebyrne 👍 Out of interest, how did you initially create the project? I use the template that comes with Serverless ( |
@hassankhan I think I did set it up using the It was the knex issues that were killing me. I have now bumped up against I will have a look at this article to find away around https://aws.amazon.com/blogs/compute/node-js-8-10-runtime-now-available-in-aws-lambda/ |
@hassankhan I have now run into the same Knex issues that it appears that you have been experiencing (seen your comments in issues threads) Would you have any working Lambda JS/TS Express/Knex implementation that you could share? I have set the |
@lukebyrne IIRC my issue was keeping connections open, this article was a massive help. |
@hassankhan I read the article but it hasnt helped me progress. Any chance you have boilerplate app lying about I code take a gander at? |
Getting the same error that just started recently for some reason. Here is the error:
Here is my serverless.yml file:
Here is my package.json file:
and my webpack.config.js file:
So far I have tried:
The weird part is that no matter which modules I put in dependencies I always get the same result on
|
We should check which one of the merges from 5.2.0 to 5.3.0 introduced the
regression.
BTW: There is a separate bug entry for the reintroduced issue (starts with
5.3.0: XXXX).
We should put all discussion in there.
…On Thu, May 30, 2019 at 8:50 PM Nick Bordeau ***@***.***> wrote:
Getting the same error that just started recently for some reason.
Here is the error:
Unable to import module 'app': Error
at Function.Module._resolveFilename (module.js:547:15)
at Function.Module._load (module.js:474:25)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/var/task/app.js:176:18)
at __webpack_require__ (/var/task/app.js:21:30)
at Module.<anonymous> (/var/task/app.js:216:27)
at __webpack_require__ (/var/task/app.js:21:30)
at /var/task/app.js:85:18
at Object.<anonymous> (/var/task/app.js:88:10)
Here is my serverless.yml file:
# Use the serverless-webpack plugin to transpile ES6
plugins:
- serverless-webpack
- serverless-domain-manager
# serverless-webpack configuration
# Enable auto-packing of external modules
custom:
webpack:
webpackConfig: ./webpack.config.js
includeModules: true
provider:
name: aws
runtime: nodejs8.10
stage: prod
apiName: partsync-prod
region: us-east-1
exclude:
- .git/**
- .env
- env.yml
- app.dev.js
- server.key
- server.crt
environment: ${file(env.yml):${self:provider.stage}}
functions:
app:
handler: app.handler
events:
- http:
path: /
method: any
cors:
origin: 'https://www.example.co' # <-- Specify allowed origin
allowCredentials: true
- http:
path: '{proxy+}'
method: any
cors:
origin: 'https://www.example.co' # <-- Specify allowed origin
allowCredentials: true
Here is my package.json file:
"devDependencies": {
***@***.***/core": "^7.4.3",
***@***.***/node": "^7.2.2",
***@***.***/plugin-proposal-class-properties": "^7.4.0",
***@***.***/plugin-proposal-object-rest-spread": "^7.4.3",
***@***.***/plugin-transform-runtime": "^7.4.3",
***@***.***/preset-env": "^7.4.3",
"babel-core": "^7.0.0-bridge.0",
"babel-eslint": "^10.0.1",
"babel-jest": "^24.7.0",
"babel-loader": "^8.0.5",
"cross-env": "^5.2.0",
"dotenv": "^6.2.0",
"eslint": "^5.16.0",
"eslint-config-airbnb": "^17.1.0",
"eslint-config-prettier": "^4.1.0",
"eslint-plugin-import": "^2.15.0",
"eslint-plugin-jsx-a11y": "^6.2.0",
"eslint-plugin-prettier": "^3.0.1",
"eslint-plugin-react": "^7.13.0",
"jest": "^24.7.0",
"mongodb-memory-server": "^3.1.3",
"morgan": "~1.9.0",
"nock": "^10.0.6",
"nodemon": "^1.18.9",
"prettier": "^1.16.4",
"serverless-domain-manager": "^2.6.13",
"serverless-webpack": "^5.2.0",
"webpack": "^4.16.2",
"webpack-node-externals": "^1.7.2"
},
"dependencies": {
***@***.***/polyfill": "^7.4.3",
***@***.***/runtime": "^7.4.3",
"bcryptjs": "^2.4.3",
"cookie-parser": "^1.4.4",
"cors": "^2.8.5",
"csvtojson": "^2.0.8",
"elasticsearch": "^15.4.1",
"express": "~4.16.0",
"helmet": "^3.16.0",
"jsonwebtoken": "^8.5.1",
"moment": "^2.24.0",
"mongodb": "^3.2.2",
"passport": "^0.4.0",
"passport-jwt": "^4.0.0",
"serverless-http": "^1.9.1",
"source-map-support": "^0.5.12",
"validator": "^10.11.0"
}
}
and my webpack.config.js file:
const slsw = require('serverless-webpack');
const nodeExternals = require('webpack-node-externals');
module.exports = {
entry: slsw.lib.entries,
mode: slsw.lib.webpack.isLocal ? 'development' : 'production',
target: 'node',
devtool: slsw.lib.webpack.isLocal ? 'inline-source-map' : 'source-map',
externals: [nodeExternals()],
optimization: {
minimize: false,
},
performance: {
hints: false,
},
module: {
rules: [
{
test: /\.js$/,
loader: 'babel-loader',
include: __dirname,
exclude: /node_modules/,
},
],
},
};
So far I have tried:
- Verifying that all dependiencies are installed.
- Deleting my node_modules folder and package-lock.json and
reinstalling all modules.
- Verified that my serverless.yml and webpack.config.js are valid
The weird part is that no matter which modules I put in dependencies I
always get the same result on sls package. Here is the output:
Time: 1133ms
Built at: 05/30/2019 2:42:57 PM
Asset Size Chunks Chunk Names
app.js 31.3 KiB 0 [emitted] app
app.js.map 50.3 KiB 0 [emitted] app
Entrypoint app = app.js app.js.map
[1] external "express" 42 bytes {0} [built]
[2] external "passport" 42 bytes {0} [built]
[3] external "bcryptjs" 42 bytes {0} [built]
[5] external "cors" 42 bytes {0} [built]
[6] external "cookie-parser" 42 bytes {0} [built]
[7] external "helmet" 42 bytes {0} [built]
[8] external "serverless-http" 42 bytes {0} [built]
[9] external "passport-jwt" 42 bytes {0} [built]
[14] external "core-js/modules/es7.array.flat-map" 42 bytes {0} [built]
[15] external "core-js/modules/es6.array.sort" 42 bytes {0} [built]
[16] external "core-js/modules/es7.promise.finally" 42 bytes {0} [built]
[17] external "core-js/modules/es7.symbol.async-iterator" 42 bytes {0} [built]
[18] external "core-js/modules/es7.string.trim-left" 42 bytes {0} [built]
[19] external "core-js/modules/es7.string.trim-right" 42 bytes {0} [built]
[20] ./app.js + 13 modules 22.9 KiB {0} [built]
| ./app.js 1.29 KiB [built]
| ./utils/auth/passport.js 529 bytes [built]
| ./routes/users.js 771 bytes [built]
| ./routes/search.js 690 bytes [built]
| ./controllers/users.js 4.81 KiB [built]
| ./controllers/search.js 3.29 KiB [built]
| ./utils/validation/users.js 5.37 KiB [built]
| ./models/users.js 1.47 KiB [built]
| ./utils/search/elasticsearchConfig.js 152 bytes [built]
| ./models/search.js 929 bytes [built]
| ./utils/search/elasticsearch.js 2.3 KiB [built]
| ./utils/validation/isEmpty.js 335 bytes [built]
| ./utils/validation/recaptcha.js 498 bytes [built]
| ./utils/db/mongodb.js 476 bytes [built]
+ 6 hidden modules
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#43?email_source=notifications&email_token=ABKEZXSTZ6QOXJ5KH3RK7NTPYAOWBA5CNFSM4CSON7OKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODWTF5FA#issuecomment-497442452>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABKEZXWJ7GQ6R77HWHQ5NPLPYAOWBANCNFSM4CSON7OA>
.
|
The related issue is #505 |
I faced a very similar problem in combination with apollo-server-lambda / @apollo/gateway. Unable to import module 'handler': Error
at Function.Module._resolveFilename (module.js:547:15)
at Function.Module._load (module.js:474:25)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at Object.<anonymous>***(/var/task/node_modules/@apollo/gateway/dist/loadServicesFromRemoteEndpoint.js:13:22)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3) Thanks to the hint that missing deps could be the cause of those kinds of errors, I was able to fix it by taking a closer look at the error message. On line 7 (***) you can see where exactly the error originated. On line 13 of the mentioned file (loadServicesFromRemoteEndpoint.js), a module was imported: const node_fetch_1 = require("node-fetch"); When running serverless package this dependency was indeed missing in the node_modules folder The solution / workaround import 'node-fetch'; This may be very specific to this rather exotic combination of federated GraphQL schemas and AWS Lambda, but I hope it can help somebody anyways, as this error may happen if any of your dependencies is missing a sub-dependency it is using in the package.json, as it seems to be the case with @apollo/gateway. |
I often have this error and I never know where to look at to fix the issue. Is there a way/tool to have more information about the error ?
I have the
SLS_DEBUG
set to true but it doesn't help.Thank you very much!
Thierry
The text was updated successfully, but these errors were encountered: