Category Archives: JavaScript

[Solved] Error: Node Sass does not yet support your current environment

2022-06-13-node-saas error

System environment

  • node -v v16.15.0
  • node-gyp -v v3.8.0
  • System Darwin 21.3.0

Screenshot of error reporting

The local code execution npm install depends on the installation items. The console displays an error message. The screenshot of the error message is as follows:

Error reporting solution

The project relies on “node-sass”: “^4.12.0”. Replace node-sass with sass

  • implementnode uninstall node-sass
  • Execute node install sass, the installation is successful. The screenshot is as follows:

The project can be started normally, and the interface is as follows:

Error report analysis:

  • The node version is 16.15.0, the system environment is the macOS m1 version, and node-sass has not yet been adapted, so the resulting
  • Replace node-sass with sass

Reference:

https://stackoverflow.com/questions/68095626/node-sass-with-apple-m1-big-sur-and-arm64

[Solved] error TS1086: An accessor cannot be declared in an ambient context

error TS1086: An accessor cannot be declared in an ambient context

Error ts1086 error resolution

After the NPM package is installed, an error is reported when running the project.

The error information is as follows

ERROR in node_modules/xxx/xxx/xxxx.d.ts(15,9): error TS1086: An accessor cannot be declared in an ambient context.

Solution:

Modify tsconfig.json file

{
  "compilerOptions": {
    "skipLibCheck": true
  }
}

Vue mutui identify (Image Verification Code)

1. Effect:

2. the plug-in reference

1) First execute the command: npm install identify to introduce the plugin package

npm install identify 

2) Configure main.js

import SIdentify  from './components/identify/identify'
Vue.use(SIdentify)

3) Write code in vue components

3.1) Components

 <div class="form-group">
            <input type="text" class="check_code" placeholder="Проверочный код" v-model="verCode" />
            <div class="login_code" @click="refreshCode">
              <!--Captcha component-->
              <Identify :identifyCode="identifyCode" ></Identify>
            </div>              
        </div>

3.2) Component js

import Identify from '@/components/identify/identify'
xport default {
  components:{Identify},
  data() {
    return {
         verCode: "",//Image verification code input box
          identifyCode:'',
          identifyCodes:'1234567890',
    };
  },
 methods:{
         randomNum(min, max) {
          return Math.floor(Math.random() * (max - min) + min);
        },
        refreshCode() {
          this.identifyCode = "";
          this.makeCode(this.identifyCodes, 4);
        },
        makeCode(o, l) {
          for (let i = 0; i < l; i++) {
            this.identifyCode += this.identifyCodes[
              this.randomNum(0, this.identifyCodes.length)
            ];
          }
        } 
},
 mounted() {
        this.identifyCode = "";
        this.makeCode(this.identifyCodes, 4);  
    },

[Solved] Vue Route Error: Uncaught TypeError: (0 , vue__WEBPACK_IMPORTED_MODULE_42__.defineComponent) is not a function

Problem Description

When running the Vue project, I used the route and found that the page had no effect. Press F12 to open the browser inspection mode, and found that the error is as follows:

Uncaught TypeError: (0 , vue__WEBPACK_IMPORTED_MODULE_42__.defineComponent) is not a function

the cause of the problem

The installed Vue routing plugin version is too high

solution

Reduce the version, use the command to npm install [email protected]install version 3.2.0 (Work for me)
and then restart the project

JavaScript Common Errors List (Reasons & Solutions)

Here is a list of the most common errors in JavaScript.

 

JavaScript Common Errors List

1.Uncaught TypeError: Cannot read property

Improper initialization of the state when reading the properties of an undefined object or calling its methods or rendering UI components will appear in the console

The simplest Solution: initialize state in the constructor.

2. TypeError: ‘undefined’ is not an object

An error occurred while reading a property or calling a method on an undefined object in safari.

3. TypeError: null is not an object

An error occurred while reading a property or calling a method on an empty object in Safari

Note: in JavaScript, null and undefined are different, which is why we see two different error messages. Undefined is usually a variable that has not been allocated, and null means the value is empty.

4.  (unknown): Script error

This kind of script error occurs when an uncaught JavaScript error (an error caused by the window.oneror handler rather than captured in the try catch) is restricted by the browser’s cross domain policy.

5. TypeError: Object doesn’t support property

The error in ie when calling an undefined method is equivalent to the “typeerror:” undefined “isnotafunction” error in chrome.

6. TypeError: ‘undefined’ is not a function

This is an error in chrome when calling an undefined function.

7. Uncaught RangeError

This error occurs when calling a recursive function that does not terminate, or if you pass a value to a function that is out of range.

8. TypeError: Cannot read property ‘length’

An error occurred while reading the length attribute of an undefined variable.

9. Uncaught TypeError: Cannot set property

When accessing an undefined variable, it always returns undefined. We cannot get or set any undefined properties.

10. ReferenceError: event is not defined

This error is raised when a variable is undefined or is outside the current scope.

[Solved] Vue3 npm ERR code ERR_SSL_DECRYPTION_FAILED_OR_BAD_RECORD_MAC

Vue3 npm ERR code ERR_SSL_DECRYPTION_FAILED_OR_BAD_RECORD_MAC

1. Vue3 create project error

vue create test1

 npm ERR! code ERR_SSL_DECRYPTION_FAILED_OR_BAD_RECORD_MAC

The detailed error is as follows:

npm ERR! code ERR_SSL_DECRYPTION_FAILED_OR_BAD_RECORD_MAC
npm ERR! 2240:error:1408F119:SSL routines:ssl3_get_record:decryption failed or bad record mac:c:\ws\deps\openssl\openssl\ssl\record\ssl3_record.c:677:
npm ERR!

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\qianle102\AppData\Local\npm-cache\_logs\2022-05-28T07_44_19_121Z-debug-0.log
 ERROR  Error: command failed: npm install --loglevel error --legacy-peer-deps
Error: command failed: npm install --loglevel error --legacy-peer-deps
    at ChildProcess.<anonymous> (C:\Users\qianle102\AppData\Roaming\npm\node_modules\@vue\cli\lib\util\executeCommand.js:138:16)
    at ChildProcess.emit (node:events:527:28)
    at ChildProcess.cp.emit (C:\Users\qianle102\AppData\Roaming\npm\node_modules\@vue\cli\node_modules\cross-spawn\lib\enoent.js:34:29)
    at maybeClose (node:internal/child_process:1092:16)
    at Process.ChildProcess._handle.onexit (node:internal/child_process:302:5)

The second error is the error of the python download command. That is, the python command is used during the installation of vue3.

If Python is not installed on this computer, an error will be reported.

2. Solutions

Download the phthon installation package and install the python framework

[Solved] Vite Error: Failed to load module script: Expected a JavaScript module script but the server…

Error message

Use the white screen of the web page packaged by vite, and the console reports an error.

Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of “text/plain”. Strict MIME type checking is enforced for module scripts per HTML spec.

reason

MIME type errors are generally a problem with native windows development. I encountered this after opening it with Python’s built-in http.server on Windows.

Solution

Deploy the packaged files in a formal server environment (such as nginx and Apache)

[Solved] Vue Project Modify Page Error: CALL_AND_RETRY_LAST Allocation failed – JavaScript heap out of memory

vue项目 CALL_AND_RETRY_LAST Allocation failed – JavaScript heap out of memory 修改页面后自动运行报错退出

Vue project: as soon as the page is modified, the automatic operation will report an error and exit (fat error: call_and_retry_last allocation failed – Javascript heap out of memory)

Solution:
step 1: NPM install -g increase memory limit
step 2: increase memory limit

Step 3: Run the project normally, if an error is reported (“node –max-old-space-size=10240″‘ is not an internal or external command, and is not a runnable program)

step 4: Look in the .bin file under node_module and replace “%_prog%” with %_prog% (without the quotes).

step 5: Run the Project normally.

[Solved] VUE Error: listen EADDRNOTAVAIL: address not available

VUE Error: listen EADDRNOTAVAIL: address not available

vue Project npm run dev Error: Error: listen EADDRNOTAVAIL: address not available …

Cause: the configured IP address is incorrect.

Solution: open the config folder and find index.js file, modify the value of host to localhost , as shown in the following figure

[Solved] vue Project Error: react lazy eslint error Parsing error: Unexpected token import

vue Project Error: react lazy eslint error Parsing error: Unexpected token import

1. You need to install the extension component eslint, and then click settings in settings – extension search – eslintrc and add this line (“parser”: “Babel-eslint”) in settings.json, save the code, and then run the project