DEV Community

ChuangWANG
ChuangWANG

Posted on

2 1

Create a npm project and install typescript dependency

Type of package installation with npm:
npm install -g packageName Install global
npm install --save -dev pacakgeName Install locally
npm install --save packageName Install locally
when run npm install --production or env variable NODE_ENV value is production, only packages in dependencies will be install, but packages in devDependencies will not.

npm install -g packageName
npm install --save-dev packageName
npm install --save packageName
Enter fullscreen mode Exit fullscreen mode

Create a new folder for this project
run npm init in the work folder above mentioned

npm init
Enter fullscreen mode Exit fullscreen mode

after we run npm init, we will get a new file named package.json,the file content as bellow:

{
  "name": "typescript-learn",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC"
}
Enter fullscreen mode Exit fullscreen mode

now we should insert code line "type": "module", in package.json to support ES5

After we insert the new code line ,the package.json as bellow:

{
  "name": "typescript-learn",
  "version": "1.0.0",
  "description": "",
  "type": "module",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC"
}

Enter fullscreen mode Exit fullscreen mode

note: let the browser support ES5 ,we can insert line as bellow:

<script type="module" src="xxxxx.js"></script>
Enter fullscreen mode Exit fullscreen mode

Now, we will install typescript dependency:
npm install typescript --save-dev

This demo location: code-repo/learn-test/typescript-learn
Git link:

SurveyJS custom survey software

JavaScript UI Library for Surveys and Forms

Generate dynamic JSON-driven forms directly in your JavaScript app (Angular, React, Vue.js, jQuery) with a fully customizable drag-and-drop form builder. Easily integrate with any backend system and retain full ownership over your data, with no user or form submission limits.

View demo

Top comments (0)

👋 Kindness is contagious

Explore a trove of insights in this engaging article, celebrated within our welcoming DEV Community. Developers from every background are invited to join and enhance our shared wisdom.

A genuine "thank you" can truly uplift someone’s day. Feel free to express your gratitude in the comments below!

On DEV, our collective exchange of knowledge lightens the road ahead and strengthens our community bonds. Found something valuable here? A small thank you to the author can make a big difference.

Okay