我已经按照webpack4示例设置了配置:https://github.com/serverless-heaven/serverless-webpack/tree/master/examples/babel-webpack-4 当我收到错误消息“找不到模块源映射支持/注册”时。
我已经研究了已经创建的问题:
https://github.com/serverless-heaven/serverless-webpack/issues/357
https://github.com/serverless-heaven/serverless-webpack/issues/228
现在我的配置是:
.babelrc{
"comments": false,
"sourceMaps": "both",
"presets": ["env","stage-2"],
"plugins": ["source-map-support"]
}
webpack.config.js:
const path = require('path');
const nodeExternals = require('webpack-node-externals');
const slsw = require('serverless-webpack');
module.exports = {
entry: slsw.lib.entries,
mode: slsw.lib.webpack.isLocal ? 'development' : 'production',
output: {
libraryTarget: 'commonjs2',
path: path.join(__dirname, '.webpack'),
filename: '[name].js',
sourceMapFilename: '[file].map',
},
optimization: {
// We no not want to minimize our code.
minimize: false,
},
performance: {
// Turn off size warnings for entry points
hints: false,
},
target: 'node',
module: {
rules: [
{
test: /\.js$/,
loader: 'babel-loader',
include: [path.join(__dirname, 'src')],
exclude: /node_modules/,
},
{
test: /\.json$/,
loader: 'json',
include: path.join(__dirname, 'src'),
},
],
},
externals: [nodeExternals()],
devtool: 'source-map',
};
package.json
{
"name": "someservice",
"version": "2.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "jest --config --colors",
"lint": "eslint . --max-warnings=0 --report-unused-disable-directives && echo '✔ Your .js files look good.'"
},
"author": "abc@gmail.com",
"license": "ISC",
"devDependencies": {
"babel": "^6.23.0",
"babel-core": "^6.26.3",
"babel-jest": "^23.4.2",
"babel-loader": "^7.1.5",
"babel-plugin-source-map-support": "^2.0.1",
"babel-plugin-transform-class-properties": "^6.22.0",
"babel-plugin-transform-es2015-modules-commonjs": "^6.26.2",
"babel-plugin-transform-inline-environment-variables": "^6.8.0",
"babel-plugin-transform-object-rest-spread": "^6.22.0",
"babel-plugin-transform-runtime": "^6.22.0",
"babel-preset-env": "^1.7.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-latest": "^6.22.0",
"babel-preset-stage-2": "^6.24.1",
"eslint": "^5.4.0",
"eslint-config-airbnb": "^17.1.0",
"eslint-config-airbnb-base": "13.1.0",
"eslint-loader": "^2.1.0",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-jest": "^21.22.0",
"eslint-plugin-jsx-a11y": "^6.1.1",
"eslint-plugin-react": "^7.1.0",
"eslint-plugin-security": "^1.4.0",
"identity-obj-proxy": "^3.0.0",
"jest": "^23.5.0",
"jest-transform-stub": "^1.0.0",
"lint-staged": "^7.2.2",
"prettier-eslint": "^8.8.2",
"prettier-eslint-cli": "^4.3.2",
"serverless-jest-plugin": "^0.1.6",
"serverless-offline": "^3.25.11",
"serverless-webpack": "^5.2.0",
"standard": "^12.0.1",
"webpack": "^4.17.3",
"webpack-node-externals": "^1.7.2",
"babel-runtime": "^6.22.0"
},
"dependencies": {
"aws-sdk": "^2.11.0",
"source-map-support": "^0.5.9"
}
}
无服务器
service: someservice
plugins:
- serverless-offline
- serverless-webpack
provider:
name: aws
runtime: nodejs6.10
region: us-east-1
stage: ${env:STAGE}
custom:
webpackConfig: ./webpack.config.js
includeModules: true
functions:
getUser:
handler: src/user/UserHandler.getUser
memory: 512
timeout: 60
events:
- http:
method: get
path: user
cors: true
integration: lambda
createUser:
handler: src/user/UserHandler.createUser
memory: 512
timeout: 60
events:
- http:
method: post
path: user
cors: true
integration: lambda
我仍然面临同样的问题。 它与 sls调用local -f 。 但是,当使用 sls deploy 部署到aws时,调用API Url时会显示错误。
npm版本:6.4.1
节点版本:v10.10.0
无服务器:1.30.3
答案 0 :(得分:0)
如果对于Webpack版本5的无服务器框架v2项目,您收到错误Cannot find module 'source-map-support/register'
,请检查concatenateModules
中webpack.config.js
的设置。禁用它,错误对我来说消失了。
module.exports = {
//...
optimization: {
concatenateModules: false
}
};
看到此问题External modules are not packaged with webpack 5。
这是我的package.json
仅供参考:
{
//...
"dependencies": {
"source-map-support": "^0.5.19"
},
"devDependencies": {
"@serverless/typescript": "^2.12.0",
"@types/aws-lambda": "^8.10.64",
"@types/node": "^14.14.6",
"@types/serverless": "^1.78.11",
"fork-ts-checker-webpack-plugin": "^6.0.0",
"serverless": "^2.13.0",
"serverless-webpack": "^5.2.0",
"ts-loader": "^8.0.10",
"ts-node": "^9.0.0",
"typescript": "^4.0.5",
"webpack": "^5.4.0",
"webpack-node-externals": "^2.5.2"
},
}
答案 1 :(得分:0)
我也遇到了同样的问题,但在安装 source-map-support
后它现在可以工作了:
yarn add source-map-support
或
npm install source-map-support