类型错误:无法读取未定义的商业属性"到小写.js



我一直在尝试用几种方法来解决这个错误,因为其他人也有类似的输出,但仍然无法完全解决。

我正在创建一个集成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)

正如我所期望的那样,每当我启动localhost时,我都会看到一条相关的错误消息,但并不完全相同(将在下面重现(
因此,我的想法是:修复VS中的错误消息,很可能也会修复这个错误消息。我设法通过添加新的声明文件来解决警告(因为那里提到的包似乎还不存在(所以,我以为是这样,然后我启动了服务器,结果和以前完全一样。

TypeError: Cannot read property 'toLowerCase' of undefined
new e
node_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-找不到模块'';反应物化';path/to/module name.js';隐式具有any类型和相关的
顺便说一句,我没有使用typescript。

提前谢谢。

我遇到了完全相同的错误,当我将.env文件移到src/文件夹外时,它就消失了。也没有使用TypeScript。

以下是一些应该很有帮助的快速步骤:

  • 转到/src文件夹
  • 并创建此文件chec-commerce.d.ts
    d告诉TypeScript这是一个声明脚本
  • 在刚刚创建的文件中,写下以下内容:
declare module '@chec/commerce';

根据导入模块的方式,这应该会清除所有错误
请确认。

替换此:

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

带有

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

我无法用其他方法解决它。

.env文件应该在src文件夹之外,它对我有效,对你也有效。。。

相关内容

最新更新