question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

V3: Bundled dependancies - module initialization error - no read access

See original GitHub issue

I’m having an issue with certain dependancies not having read access and that causes errors on deployed lambda. Error:

module initialization error: Error
at Error (native)
at Object.fs.openSync (fs.js:641:18)
at Object.fs.readFileSync (fs.js:509:33)
at Object.Module._extensions..js (module.js:578:20)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/var/task/node_modules/rest-facade/src/index.js:2:11)

locally when installing with npm the rest-facade module has the correct permissions for all files in /src when its packaged with the plugin it doesn’t:

packaged /node_modules/rest-facade/src/:

13799175 -rw-------  1 amitay  admin  9993 Dec 31  1979 Client.js
13799176 -rw-------  1 amitay  admin   207 Dec 31  1979 defaultOptions.js
13799177 drwxr-xr-x  2 amitay  admin   170 Aug 16 11:45 exceptions
13799181 -rw-r--r--  1 amitay  admin   154 Dec 31  1979 index.js
13799182 -rw-------  1 amitay  admin    38 Dec 31  1979 mocha.opts
13799183 -rw-------  1 amitay  admin   389 Dec 31  1979 utils.js

project /node_modules/rest-facade/src/:

12991081 -rw-r--r--  1 amitay  admin  9993 Oct 19  2016 Client.js
12991079 -rw-r--r--  1 amitay  admin   207 Oct 19  2016 defaultOptions.js
12980542 drwxr-xr-x  2 amitay  admin   170 Aug 13 17:44 exceptions
12991080 -rw-r--r--  1 amitay  admin   154 Mar 28 18:30 index.js
12991084 -rw-r--r--  1 amitay  admin    38 Oct 19  2016 mocha.opts
12991083 -rw-r--r--  1 amitay  admin   389 Oct 19  2016 utils.js

using: webpack: ^3.5.4 serverless-webpack: ^3.0.0-rc.1 serverless: 1.19.0

webpack.config.js:

const path = require('path');
const slsw = require('serverless-webpack');
const nodeExternals = require('webpack-node-externals');

module.exports = {
    entry: slsw.lib.entries,
    target: 'node',
    externals: [nodeExternals({
        modulesFromFile: true
    })],
    module: {
        rules: [
            {
                test: /\.jql$/,
                exclude: /node_modules/,
                use: ['jql-loader', 'babel-loader']
            },
            {
                test: /\.jsx?$/,
                exclude: /node_modules/,
                use: ['shebang-loader', 'babel-loader']
            },
            {
                test: /\.json$/,
                use: ['json-loader']
            }
        ]
    },
    output: {
        libraryTarget: 'commonjs',
        path: path.join(__dirname, '.webpack'),
        filename: '[name].js'
    }
};

serverless.yml:

plugins:
  - serverless-webpack
  - serverless-dynamodb-local
  - serverless-s3-local
  - serverless-offline-scheduler
  - serverless-offline
  - serverless-mocha-plugin
  - api-docs // custom plugin

package:
  include:
    - node_modules/**
    - yarn.lock
  exclude:
    - .git
    - .requirements
    - .ses-mailbox
    - apidoc.json
    - apidoc_shared.js
    - docs
    - cfn_lambda_helpers
    - seed
    - test
  individually: true

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
amitaymolkocommented, Aug 16, 2017

Yes, I think 644 would be perfect.

0reactions
HyperBraincommented, Apr 11, 2018

The reason for that is, that Serverless (the framework itself) optimizes uploads by checking the ZIP file hash. So if a file is recreated by webpack, it would generate a ZIP with a different hash, even if the compiled file did not change. So the dates are set to “0” or unset, so that the ZIP hash is only dependent on the real content. However, the modification date of the ZIP file itself states the packaging time.

Read more comments on GitHub >

github_iconTop Results From Across the Web

module initialization error - no read access · Issue #648 - GitHub
Invoking my lambda shows a EACCES: permission denied, ... V3: Bundled dependancies - module initialization error - no read access #190 ...
Read more >
Troubleshoot Lambda deployment package upload errors - AWS
When I try to upload my AWS Lambda deployment package, I get either a permission denied or unable to import module error. How...
Read more >
Import libraries in lambda layers - python - Stack Overflow
I wanted to import jsonschema library in my AWS Lambda in order to perform request validation. Instead of bundling ...
Read more >
Module Federation - webpack
webpack is a module bundler. Its main purpose is to bundle JavaScript files for usage in a browser, yet it is also capable...
Read more >
package.json - npm Docs
In npm versions 3 through 6, peerDependencies were not automatically installed, and would raise a warning if an invalid version of the peer...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found