laravel - laravel/vuejs mix 中 jsPDF 的 Webpack 错误
问题描述
因此,我尝试在我的项目中使用 jsPDF,但是每当我尝试将 jsPDF 导入到我的 vue 组件时,我都会收到此错误:
ERROR in ./node_modules/canvg/lib/index.es.js 1933:16-23
Module not found: Error: Can't resolve 'process/browser' in '/Users/air-1/Desktop/OneDrive - laravel projects/prevzemniDokumenti/node_modules/canvg/lib'
Did you mean 'browser.js'?
BREAKING CHANGE: The request 'process/browser' failed to resolve only because it was resolved as fully specified
(probably because the origin is strict EcmaScript Module, e. g. a module with javascript mimetype, a '*.mjs' file, or a '*.js' file where the package.json contains '"type": "module"').
The extension in the request is mandatory for it to be fully specified.
Add the extension to the request.
webpack compiled with 1 error
现在它说我必须将扩展名添加到请求中,但我不知道这意味着什么...试图寻找解决方案但我找不到所以现在我在这里。
我的 package.json
{
"private": true,
"scripts": {
"dev": "npm run development",
"development": "mix",
"watch": "mix watch",
"watch-poll": "mix watch -- --watch-options-poll=1000",
"hot": "mix watch --hot",
"prod": "npm run production",
"production": "mix --production"
},
"devDependencies": {
"autoprefixer": "^10.3.7",
"axios": "^0.21",
"jquery": "^3.6",
"laravel-mix": "^6.0.6",
"lodash": "^4.17.19",
"popper.js": "^1.16.1",
"postcss": "^8.3.9",
"resolve-url-loader": "^3.1.2",
"tailwindcss": "^2.2.16",
"vue": "^2.6.12",
"vue-loader": "^15.9.8",
"vue-template-compiler": "^2.6.12"
},
"dependencies": {
"jspdf": "^2.4.0",
"vue-router": "^3.5.2"
}
}
我该如何解决这个错误?
解决方案
找到了解决方案。
在 webpack.mix.js 我必须添加
mix.options({legacyNodePolyfills: false})
在 mix.js 调用之前
推荐阅读
- r - 用负比例拟合 log pearson III 的问题
- javascript - requestAnimationFrame 似乎无效
- javascript - 按月份和日期的总值对数组进行排序 - Angular
- python - sort list alphabetically by field in python
- react-native - FlatList 底部的 TextInput 元素存在问题
- python - 如何使用从 API 传递的多个过滤器的 lambda 函数查询 dynamoDB
- amazon-web-services - ECS Fargate 新版任务定义
- sapui5 - SAPUI5中如何给Token添加操作?
- python - 如何在 jupyter 实验室笔记本中导入解决方案
- python - PyQt5:如何重置 QtWidgets.QGroupBox 的内容