亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

類型錯誤:無法使用 commerce.js 讀取未定義的屬性“toLowerCase”

類型錯誤:無法使用 commerce.js 讀取未定義的屬性“toLowerCase”

慕容708150 2023-11-12 14:29:57
我一直在嘗試用多種方法解決這個錯誤,因為其他人也有類似的輸出,但仍然無法完全做到。我正在創建一個集成 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' 隱式具有任何類型和相關順便說一句,我沒有使用打字稿。
查看完整描述

4 回答

?
慕田峪9158850

TA貢獻1794條經驗 獲得超7個贊

我遇到了完全相同的錯誤,當我將 .env 文件移到 src/ 文件夾之外時,它就消失了。也不使用 TypeScript。



查看完整回答
反對 回復 2023-11-12
?
哈士奇WWW

TA貢獻1799條經驗 獲得超6個贊

替換這個:

export const commerce = new Commerce(process.env.REACT_APP_CHEC_PUBLIC_KEY, true);

export const commerce = new Commerce('PUBLIC_API_KEY', true);

我無法以任何其他方式修復它。


查看完整回答
反對 回復 2023-11-12
?
胡子哥哥

TA貢獻1825條經驗 獲得超6個贊

以下是一些應該會有所幫助的快速步驟:

  • 轉到/src文件夾

  • 并創建這個文件chec-commerce.d.ts
    告訴dTypeScript 這是一個聲明腳本。

  • 在剛剛創建的文件中,寫入以下內容:

declare module '@chec/commerce';

根據您導入模塊的方式,這應該會清除所有錯誤。
請確認。


查看完整回答
反對 回復 2023-11-12
?
紫衣仙女

TA貢獻1839條經驗 獲得超15個贊

.env 文件應該位于 src 文件夾之外,它對我有用,它也對你有用......



查看完整回答
反對 回復 2023-11-12
  • 4 回答
  • 0 關注
  • 201 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號