首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >package.json在/package.json不存在

package.json在/package.json不存在
EN

Stack Overflow用户
提问于 2021-01-11 11:48:32
回答 1查看 719关注 0票数 2

当我试图使用webpack来构建我的项目并在AWS上使用它时,我收到了许多与./node_modules/grpc.的关键依赖项相关的警告。这个问题一旦我import {GoogleAdsApi} from 'google-ads-api';就会发生,据我所知,这与动态导入有关,我可能错了。因此,绑定的文件是巨大的(超过4MB),当压缩它并在Lambda上使用它时,当触发Lambda时,我会得到以下错误:"package.json不存在于/package.json上“

*打字本

*节点V12.x

index.ts

代码语言:javascript
复制
import {GoogleAdsApi} from 'google-ads-api';

export const handler = async (event: any): Promise<any> => {
  try {
    console.log('Start', event);
    // @ts-ignore
    const api = new GoogleAdsApi({client_id: 'id', client_secret: 'secret', developer_token: 'dToken'});
    return 'success';
  } catch (e) {
    console.log('Error', e);
    throw e;
  }
};
代码语言:javascript
复制
Error: package.json does not exist at /package.json,
at Object.exports.find (/var/task/webpack:/node_modules/node-pre-gyp/lib/pre-binding.js:18:1),
at Object.<anonymous> (/var/task/webpack:/node_modules/grpc/src/grpc_extension.js:29:1),
at Object.<anonymous> (/var/task/index.js:40079:30),
at __webpack_require__ (/var/task/webpack:/webpack/bootstrap:19:1),
at Object.<anonymous> (/var/task/webpack:/node_modules/grpc/src/client_interceptors.js:144:12),
at __webpack_require__ (/var/task/webpack:/webpack/bootstrap:19:1),
at Object.<anonymous> (/var/task/webpack:/node_modules/grpc/src/client.js:35:27),
at __webpack_require__ (/var/task/webpack:/webpack/bootstrap:19:1),
at Object.<anonymous> (/var/task/webpack:/node_modules/grpc/index.js:27:14),
at Object.<anonymous> (/var/task/index.js:2460:30)

Webpack警告 Webpack警告:

代码语言:javascript
复制
WARNING in ./node_modules/bytebuffer/dist/bytebuffer-node.js 29:38-55
Module not found: Error: Can't resolve 'memcpy' in   

WARNING in ./node_modules/google-ads-node/node_modules/import-fresh/index.js 28:8-25
Critical dependency: the request of a dependency is an expression


WARNING in ./node_modules/grpc/src/grpc_extension.js 32:12-33
Critical dependency: the request of a dependency is an expression


WARNING in ./node_modules/node-pre-gyp/lib/pre-binding.js 20:22-48
Critical dependency: the request of a dependency is an expression

WARNING in ./node_modules/node-pre-gyp/lib/util/versioning.js 17:20-67
Critical dependency: the request of a dependency is an expression

webpack.config.js:

代码语言:javascript
复制
`const path = require("path")
const ForkTsCheckerWebpackPlugin = require("fork-ts-checker-webpack-plugin")

module.exports = {
mode: "production",
entry: "./src/index.ts",
resolve: {
extensions: [".js", ".jsx", ".json", ".ts", ".tsx"],
},
output: {
libraryTarget: "commonjs",
path: path.join(__dirname, "dist"),
filename: "index.js",
},
target: "node",
module: {
rules: [
{
// Include ts, tsx, js, and jsx files.
test: /.(ts|js)x?$/,
exclude: /node_modules/,
use: [
{
loader: "cache-loader",
options: {
cacheDirectory: path.resolve(".webpackCache"),
},
},
"babel-loader",
],
},
],
},
plugins: [new ForkTsCheckerWebpackPlugin()],
}`
EN

回答 1

Stack Overflow用户

发布于 2022-12-02 14:56:53

不确定这是否仍然相关,但我认为您应该使用esbuild和添加依赖项作为dev。应该减少你的包的大小,并解决你的问题

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65666326

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档