我在 src/boot/amplify.js
中为 Quasar 创建了以下引导文件,并将 'amplify'
添加到 quasar.conf.js
:
import Amplify from 'aws-amplify';
import awsconfig from '../aws-exports';
import {
applyPolyfills,
defineCustomElements,
} from '@aws-amplify/ui-components/loader';
applyPolyfills().then(() => {
defineCustomElements(window);
});
Amplify.configure(awsconfig);
但是我从行 import Amplify from 'aws-amplify';
中得到很多导入错误:
Module not found: Can't resolve imported dependency "./printError"
App • ERROR • UI in ./node_modules/graphql/error/GraphQLError.mjs
还有更多——我已经通过 npm install --save graphql
传递了它们,但随后我发现了更多导入错误。使用 Vue 3 CLI 而不是 Quasar 可以很容易地按照 Amplify 文档进行设置。
有没有人幸运地使用过 Quasar 或者知道可能的解决方案是什么?
最佳答案
是一个 webpack 问题,检查这个: https://github.com/graphql/graphql-js/issues/2721#issuecomment-723008284
我通过添加到 quasar.conf.js 解决了它
build: {
...
extendWebpack (cfg, {isServer, isClient}) {
cfg.module.rules.push ({
test: /\.m?js/,
resolve: {
fullySpecified: false,
fallback: {crypto: false}
}
})
}
}
}
“后备:{crypto: false}” 用于解决后续关于crypto-js依赖缺失的错误,基于: https://stackoverflow.com/a/67076572/1550140
关于amazon-web-services - 如何将 Quasar 2 与 AWS Amplify 结合使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68330062/