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

Runtime.ImportModuleError: Error: Cannot find module '@babel/runtime-corejs3/core-js-stable/json/stringify' #1650

Open
juztinlazaro opened this issue Nov 10, 2023 · 5 comments

Comments

@juztinlazaro
Copy link

juztinlazaro commented Nov 10, 2023

Hi im having an error, lodash can't find

image

serverless deploy success but when i hit the api endpoint im having an issue in handler

aws lambda code

/******/ (() => { // webpackBootstrap
/******/ 	"use strict";
/******/ 	// The require scope
/******/ 	var __webpack_require__ = {};
/******/ 	
/************************************************************************/
/******/ 	/* webpack/runtime/compat get default export */
/******/ 	(() => {
/******/ 		// getDefaultExport function for compatibility with non-harmony modules
/******/ 		__webpack_require__.n = (module) => {
/******/ 			var getter = module && module.__esModule ?
/******/ 				() => (module['default']) :
/******/ 				() => (module);
/******/ 			__webpack_require__.d(getter, { a: getter });
/******/ 			return getter;
/******/ 		};
/******/ 	})();
/******/ 	
/******/ 	/* webpack/runtime/define property getters */
/******/ 	(() => {
/******/ 		// define getter functions for harmony exports
/******/ 		__webpack_require__.d = (exports, definition) => {
/******/ 			for(var key in definition) {
/******/ 				if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
/******/ 					Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
/******/ 				}
/******/ 			}
/******/ 		};
/******/ 	})();
/******/ 	
/******/ 	/* webpack/runtime/hasOwnProperty shorthand */
/******/ 	(() => {
/******/ 		__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
/******/ 	})();
/******/ 	
/******/ 	/* webpack/runtime/make namespace object */
/******/ 	(() => {
/******/ 		// define __esModule on exports
/******/ 		__webpack_require__.r = (exports) => {
/******/ 			if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ 				Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ 			}
/******/ 			Object.defineProperty(exports, '__esModule', { value: true });
/******/ 		};
/******/ 	})();
/******/ 	
/************************************************************************/
var __webpack_exports__ = {};
// ESM COMPAT FLAG
__webpack_require__.r(__webpack_exports__);

// EXPORTS
__webpack_require__.d(__webpack_exports__, {
  "handler": () => (/* binding */ handler)
});

;// CONCATENATED MODULE: external "@babel/runtime-corejs3/core-js-stable/json/stringify"
const stringify_namespaceObject = require("@babel/runtime-corejs3/core-js-stable/json/stringify");
var stringify_default = /*#__PURE__*/__webpack_require__.n(stringify_namespaceObject);
;// CONCATENATED MODULE: ./serverless_v3/functions/home/handler.js

const handler = async event => {
  console.log('test===', event);
  return {
    statusCode: 200,
    body: stringify_default()({
      message: 'Go Serverless v3.0! Your function executed successfully!',
      input: event
    }, null)
  };
};
module.exports = __webpack_exports__;
/******/ })()
;
//# sourceMappingURL=handler.js.map

for some reason, in aws lambda it adds

;// CONCATENATED MODULE: external "@babel/runtime-corejs3/core-js-stable/json/stringify"
const stringify_namespaceObject = require("@babel/runtime-corejs3/core-js-stable/json/stringify");
var stringify_default = /*#__PURE__*/__webpack_require__.n(stringify_namespaceObject);
;// CONCATENATED MODULE: ./serverless_v3/functions/home/handler.js

Runtime.ImportModuleError: Error: Cannot find module '@babel/runtime-corejs3/core-js-stable/json/stringify'

image

Additional Data

plugins:
 - serverless-offline-ssm
- serverless-domain-manager
- serverless-webpack
- serverless-offline

//webpack.config

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

module.exports = {
  entry: slsw.lib.entries,
  target: 'node',
  mode: slsw.lib.webpack.isLocal ? 'development' : 'production',
  resolve: {
    alias: {
      lib: path.resolve(__dirname, 'lib/'),
      services: path.resolve(__dirname, 'services/'),
      builders: path.resolve(__dirname, 'builders/'),
      constants: path.resolve(__dirname, 'constants/'),
      config: path.resolve(__dirname, 'config/'),
      shared: path.resolve(__dirname, '../shared/'),
    },
  },
  optimization: {
    // We no not want to minimize our code.
    minimize: false,
  },
  performance: {
    // Turn off size warnings for entry points
    hints: false,
  },
  devtool: 'nosources-source-map',
  externals: [nodeExternals()],
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        use: [
          {
            loader: 'babel-loader',
          },
        ],
      },
    ],
  },
  output: {
    libraryTarget: 'commonjs2',
    path: path.join(__dirname, '.webpack'),
    filename: '[name].js',
    sourceMapFilename: '[file].map',
  },
};

//handler

module.exports.handler = async (event) => {
  return {
    statusCode: 200,
    body: JSON.stringify(
      {
        message: 'Go Serverless v3.0! Your function executed successfully!',
        input: event,
      },
      null,
    ),
  };
};

//function

api:
  name: apiv3test
  handler: ${self:custom.functions}/home/handler.handler
  events:
    - httpApi:
        path: /
        method: get
  • Serverless-Webpack Version you're using: "serverless-webpack": "5.3.0",
  • Webpack version you're using: "webpack": "5.81.0",
  • Serverless Framework Version you're using: "serverless": "3.36.0",
  • Operating System:
  • Stack Trace (if available):
@j0k3r
Copy link
Member

j0k3r commented Nov 13, 2023

Well, what can we do?
Do you think the problem is cristal clear for us and we could provide a direct fix? No.
We need a lot of more information you removed from the default template.

Also, we might need to see some source code to understand the problem.
Without that, we really can't help you.

@juztinlazaro
Copy link
Author

juztinlazaro commented Nov 13, 2023

Hi @j0k3r just update the details thanks, hopefully it add more info thanks

@juztinlazaro juztinlazaro changed the title Runtime.ImportModuleError: Error: Cannot find module '@babel/runtime-corejs3/core-js-stable/instance/map' Runtime.ImportModuleError: Error: Cannot find module '@babel/runtime-corejs3/core-js-stable/json/stringify' Nov 13, 2023
@juztinlazaro
Copy link
Author

for some reason i need to forceInclude the dependencies

webpack:
  webpackConfig: serverless_v3/webpack.config.js
  includeModules:
    forceInclude:
      - lodash
      - moment
      - es6-promisify
  packager: 'yarn'
  concurrency: 5 # desired concurrency, defaults to the number of available cores
  serializedCompile: true # backward compatible, this translates to concurrency: 1

@j0k3r
Copy link
Member

j0k3r commented Nov 14, 2023

What's your full webpack configuration from serverless.yml?

@juztinlazaro
Copy link
Author

juztinlazaro commented Nov 14, 2023

Hi @j0k3r

webpack:
  webpackConfig: serverless_v3/webpack.config.js
  packager: 'yarn'
  includeModules: true

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

2 participants