我一直在嘗試用多種方法解決這個錯誤,因為其他人也有類似的輸出,但仍然無法完全做到。我正在創建一個集成 commerce.js 的電子商務網站,從“@chec/commerce.js”導入后,我收到了警告(VS):Could not find a declaration file for module '@chec/commerce.js'. '/Users/e-commerce/node_modules/@chec/commerce.js/lib/index.js' implicitly has an 'any' type. Try `npm install @types/chec__commerce.js` if it exists or add a new declaration (.d.ts) file containing `declare module '@chec/commerce.js';`ts(7016)每當我觸發本地主機時,正如我所期望的那樣,我都會看到一條相關的錯誤消息,但并不完全相同(將在下面重現)。因此我的想法是:修復 VS 中的錯誤消息,很可能也會修復這個問題。我設法通過添加新的聲明文件來解決警告(因為似乎提到的包還不存在)所以,我認為是這樣,然后我啟動了服務器,輸出與以前完全相同。TypeError: Cannot read property 'toLowerCase' of undefinednew enode_modules/@chec/commerce.js/lib/index.js:1現在,顯然是node_modules 中文件index.js 的第一行。好吧,那它說了什么?(為了以防萬一,我會在這里寫不止第一行) var _objectWithoutProperties=require("@babel/runtime/helpers/objectWithoutProperties"),_toConsumableArray=require("@babel/runtime/helpers/toConsumableArray"),_typeof=require("@babel/runtime/helpers/typeof"),_defineProperty=require("@babel/runtime/helpers/defineProperty"),_classCallCheck=require("@babel/runtime/helpers/classCallCheck"),_createClass=require("@babel/runtime/helpers/createClass"),_regeneratorRuntime=require("@babel/runtime/regenerator"),_asyncToGenerator=require("@babel/runtime/helpers/asyncToGenerator"),axios=require("axios");function _interopDefaultLegacy(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}但這不是唯一的一個,下面還有另一個抱怨商務模塊的問題Module.<anonymous>src/lib/commerce.js:4 1 | // @ts-ignore 2 | import Commerce from "@chec/commerce.js"; 3 | > 4 | export const commerce = new Commerce( 5 | process.env.REACT_APP_CHEC_PUBLIC_KEY, 6 | true 7 | );好吧,現在我對仍然看到的錯誤消息有點困惑,因此想聽聽您認為這可能是什么問題?我也在這里查看了一些帖子,例如Typescript React - Could not find a declaration file for module ''react-materialize'。'path/to/module-name.js' 隱式具有任何類型和相關順便說一句,我沒有使用打字稿。
類型錯誤:無法使用 commerce.js 讀取未定義的屬性“toLowerCase”
慕容708150
2023-11-12 14:29:57