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

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

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

以下是已翻译的内容:

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:

# 初始化 package.json
npm init
# 安装 Next.js 依赖
npm install next@12.3.4 react react-dom
// 在 package.json 中编辑 Next.js 脚本
"scripts": {
  "dev": "next dev",
  "build": "next build",
  "start": "next start",
  "lint": "next lint"
}
# 创建文件结构
.
├── package.json
├── pages
│   ├── index.js
// 初始化你的 index.js
import React from "react";

function index() {
  return <div>Hello world</div>;
}

export default index;
# 启动 Next.js
npm run dev
英文:

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

# init the package.json
npm init
# intall next dependencies
npm install next@12.3.4 react react-dom
// edit your package.json with next scripts
&quot;scripts&quot;: {
  &quot;dev&quot;: &quot;next dev&quot;,
  &quot;build&quot;: &quot;next build&quot;,
  &quot;start&quot;: &quot;next start&quot;,
  &quot;lint&quot;: &quot;next lint&quot;
}
# create the file structure
.
├── package.json
├── pages
│   ├── index.js
// init your index.js
import React from &quot;react&quot;;

function index() {
  return &lt;div&gt;Hello world&lt;/div&gt;;
}

export default index;
# start next
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:

确定