简体   繁体   English

TypeError:无法使用 commerce.js 读取未定义的属性“toLowerCase”

[英]TypeError: Cannot read property 'toLowerCase' of undefined with commerce.js

I have been trying to solve this error with several ways, since other people had similar outputs, but still couldn't do it completely.我一直在尝试用几种方法解决这个错误,因为其他人有类似的输出,但仍然无法完全做到。

I am creating an e-commerce site integrating commerce.js, after importing from '@chec/commerce.js' I had a warning (VS):我正在创建一个集成 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)

Whenever I fired the localhost, as I was expecting, I saw a related error message, not exactly the same though (will reproduce it below).每当我触发 localhost 时,正如我所料,我看到了一条相关的错误消息,但并不完全相同(将在下面重现)。
Therefore my thought was: fixing the error message in VS, will most likely fix this one as well.因此我的想法是:修复 VS 中的错误消息,很可能也会修复这个错误消息。 I manage to solve the warning by adding the new declaration file (because it seems that the package mentioned there doesn't exist yet) So, I thought it was that, then I fired the server and the output is exactly the same as before.我设法通过添加新的声明文件来解决警告(因为似乎提到的 package 尚不存在)所以,我以为是这样,然后我解雇了服务器,output 与以前完全相同。

TypeError: Cannot read property 'toLowerCase' of undefined
new e
node_modules/@chec/commerce.js/lib/index.js:1

Now, apparently is the first line of the file index.js in node_modules.现在,显然是 node_modules 中文件 index.js 的第一行。 Ok, what does it say then?好的,那它说什么? (I will write here more than only the first line, just in case) (为了以防万一,我会在这里写不止第一行)


    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}}

But this is not the only one, below, another one complaining about the commerce module still但这不是唯一的,下面还有一个抱怨商务模块的人

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 | );

Well, now I am a bit confused about the error messages that I still see, and therefore would like to hear what do you think it could be the problem?好吧,现在我对仍然看到的错误消息有点困惑,因此想听听您认为这可能是什么问题?

I check some posts here as well, such as Typescript react - Could not find a declaration file for module ''react-materialize'.我也在这里查看了一些帖子,例如Typescript react - 找不到模块“react-materialize”的声明文件。 'path/to/module-name.js' implicitly has an any type and related 'path/to/module-name.js' 隐含任何类型和相关
By the way, I am not using typescript.顺便说一句,我没有使用 typescript。

Thank you in advance.先感谢您。

I had the exact same error, it went away as soon as I moved the.env file outside the src/ folder.我遇到了完全相同的错误,只要我将 .env 文件移到 src/ 文件夹之外,它就消失了。 Not using TypeScript either.也不使用 TypeScript。

Here are some quick steps that should proly help:以下是一些应该能提供帮助的快速步骤:

  • Go the /src folder Go /src文件夹
  • And create this file chec-commerce.d.ts并创建此文件chec-commerce.d.ts
    The d tells TypeScript that this is a declaration script. d告诉 TypeScript 这是一个声明脚本。
  • Inside the just created file, write this:在刚刚创建的文件中,这样写:
declare module '@chec/commerce';

Based on how you are importing the module, this should clear all the errors.根据您导入模块的方式,这应该会清除所有错误。
Kindly confirm.请确认。

Replace this:替换这个:

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

with

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

I couldn't fix it any other way.我无法以任何其他方式解决它。

.env file should outside the src folder and its work for me its will also work for you too... .env 文件应该在 src 文件夹之外,它对我有用,它也对你有用......

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 angular js TypeError:无法读取未定义的属性“ toLowerCase” - angular js TypeError: Cannot read property 'toLowerCase' of undefined angular-sanitize.js:6 TypeError: 无法读取未定义的属性“toLowerCase” - angular-sanitize.js:6 TypeError: Cannot read property 'toLowerCase' of undefined 未捕获的TypeError:无法读取属性toLowerCase的未定义 - Uncaught TypeError: Cannot read property toLowerCase of undefined 类型错误:无法在反应中读取未定义的属性“toLowerCase” - TypeError: Cannot read property 'toLowerCase' of undefined in react 茉莉花:TypeError:无法读取未定义的属性“ toLowerCase” - Jasmine: TypeError: Cannot read property 'toLowerCase' of undefined 未捕获的TypeError:无法读取未定义的属性“ toLowerCase” - Uncaught TypeError: Cannot read property 'toLowerCase' of undefined 未捕获的TypeError无法读取未定义的属性“ toLowerCase” - Uncaught TypeError Cannot read property 'toLowerCase' of undefined 未捕获的TypeError:无法读取未定义的属性'toLowerCase' - Uncaught TypeError: Cannot read property 'toLowerCase' of undefined 面对错误core.js:15723错误TypeError:无法读取Angular 7中未定义的属性“ toLowerCase” - Facing error core.js:15723 ERROR TypeError: Cannot read property 'toLowerCase' of undefined In Angular 7 为什么我得到:TypeError:无法读取未定义的属性“toLowerCase”(React JS) - Why did I get: TypeError: Cannot read property 'toLowerCase' of undefined (React JS)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM