如何在使用版本13而不是版本12创建next-app

huangapple go评论121阅读模式
英文:

How to create-next-app using version 12 instead of version 13

问题

我将要在Udemy上跟进一个新的课程,这个课程是关于使用React创建网站的。https://www.udemy.com/course/build-the-best-ecommerce-website-ever-with-react-js-next-js/ 就是这个课程。问题是,讲师正在使用Next.js版本12,但当我现在创建一个Next.js项目时,它会使用13.1版本,而且有很大的差异。我该如何解决这个问题?并且在终端上进行时是否可以使用Yarn。

我查阅了文档,但找不到关于这个的指南,我认为只是从package.json文件中操作可能会在以后引发问题,所以我不知道该怎么办。

英文:

I am going to follow a new course in udemy and it is about creating a website with react. https://www.udemy.com/course/build-the-best-ecommerce-website-ever-with-react-js-next-js/ that is the course. The problem is, instructor is using Next.js version 12 and when I create a next.js now it will create with 13.1 version but there is drastic differences. How can I overcome this ? and is it possible to use yarn while doing it from terminal.

I looked to documentation but couldn't find a guide about this and I thought that just doing it from package.json would create problems later so I don't know what to do .

答案1

得分: 15

以下是已翻译的内容:

  1. npx create-next-app@12 <app-name> && cd <app-name> && npm i next@12
英文:

Use the following commands (taken from here):

<!-- language: bash -->
npx create-next-app@12 <app-name> && cd <app-name> && npm i next@12

答案2

得分: 13

以下是翻译好的内容,代码部分未做翻译:

"It's possible to setup Next.js version 12 manually:

  1. # 初始化 package.json
  2. npm init
  1. # 安装 Next.js 依赖
  2. npm install next@12.3.4 react react-dom
  1. // 在 package.json 中编辑 Next.js 脚本
  2. "scripts": {
  3. "dev": "next dev",
  4. "build": "next build",
  5. "start": "next start",
  6. "lint": "next lint"
  7. }
  1. # 创建文件结构
  2. .
  3. ├── package.json
  4. ├── pages
  5. ├── index.js
  1. // 初始化你的 index.js
  2. import React from "react";
  3. function index() {
  4. return <div>Hello world</div>;
  5. }
  6. export default index;
  1. # 启动 Next.js
  2. npm run dev
英文:

It's possible to setup Next.js version 12 manually:

  1. # init the package.json
  2. npm init
  1. # intall next dependencies
  2. npm install next@12.3.4 react react-dom
  1. // edit your package.json with next scripts
  2. &quot;scripts&quot;: {
  3. &quot;dev&quot;: &quot;next dev&quot;,
  4. &quot;build&quot;: &quot;next build&quot;,
  5. &quot;start&quot;: &quot;next start&quot;,
  6. &quot;lint&quot;: &quot;next lint&quot;
  7. }
  1. # create the file structure
  2. .
  3. ├── package.json
  4. ├── pages
  5. ├── index.js
  1. // init your index.js
  2. import React from &quot;react&quot;;
  3. function index() {
  4. return &lt;div&gt;Hello world&lt;/div&gt;;
  5. }
  6. export default index;
  1. # start next
  2. npm run dev

答案3

得分: 0

npx create-next-app@12 .
for now is the only solution but indirectly it already uses YARN under the hood

英文:

npx create-next-app@12 .
for now is the only solution but indirectly it already uses YARN under the hood

huangapple
  • 本文由 发表于 2023年2月16日 18:03:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/75470624.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定