Tag Archives: ts

VSCode Terminal Execute tsc Commands Error [Solved]

1. Problem description

When the vscode terminal executes the TSC instruction to compile the TS document, an error is reported as follows:

2. Causes of problems

Vscode terminal cannot use command

3. Solutions

1. Right click the vscode icon and select run as administrator;

2. Run code on vscode terminal

get-ExecutionPolicy

Restricted is displayed, indicating that the terminal is prohibited from using the command;

3. Rerun the code

set-ExecutionPolicy RemoteSigned

4. Execute again at this time

get-ExecutionPolicy

If remotesigned is displayed, it means that the terminal command can be used

4. Implementation effect

Error: Projects must list all files or use an ‘include‘ pattern.

When importing a file, the file clearly exists but an error is reported:

File 'xxx/packages/@vue/src/use-list.ts' is not listed within the file list of project 'xxx/packages@/vue/tsconfig.json'. Projects must list all files or use an 'include' pattern.

resolvent:

  stay   Is not listed within the file to add or modify a regular path to the include in the file indicated.

At present, the file indicating the path regularity problem is tsconfig.json, so go to the tsconfig.json file to view the include item.

tsconfig.json:

{
  "include": ["src"],
}

Modified tsconfig.json:

{
  "include": ["src/**/*.ts"],
}

[Solved] TS Error: Could not find a declaration file for module

Some NPM packages have no problem using native JS, and some packages will report “could not find a declaration file for module” error after changing ts.

There are two ways to solve this problem

1. Download the @ type/error reporting package (some package developers may not upload their own. D.ts code to the NPM branch, then they will report an error saying that they can’t find this package, don’t worry about the next step)

2. The most direct, simple and effective solution: create a new shims-vue.d.ts file in the root directory of the project

//declare declaration declares an ambient module (i.e., a module declaration without internal implementation) 
declare module '*.vue' {
  import Vue from 'vue'
  export default Vue
}
 
 
declare module 'XX'
// xx is the name of the package that your package cannot find declared

The only thing to note is that after the first creation of the file with vscode, it should be restarted to see the effect, and then it will take effect. After the declaration is saved, the error will disappear immediately.

Cannot find name ‘require’

In Typescript, direct use of the require syntax in the case of unconfigured error ‘Cannot find name’ require ‘

why
Require is the syntax for node, and the runtime environment is not the Node environment.
plan
1. Install @types/node: NPM I @types/ node-s-d
2. Json :
compilerOptions add an item:

{
    "compilerOptions": {
    	// ...
        "types": ["node"],
        // ...
}