我们采用了以下项目结构
|- pages
|- <page_name>
|- index.js # To do a default export of the main component
|- MainComponent.jsx # Contains other subcomponents
|- main-component.css # CSS for the main component
|- OtherComponents.jsx # more than 1 file for child components that are used only in that page
|- __tests__ # Jest unit and snapshot tests
|- components
|- index.js # Exports all the default components of each component as named exports
|- CommonCmpnt1
|- CommonCmpnt1.jsx
|- common-cmpnt-1.css
|- index.js …Run Code Online (Sandbox Code Playgroud) 我正在尝试将表单数据保存到 Next.js 中的电子表格中,但我不断收到此错误,该错误在导入后立即出现google-spreadsheet
错误
./node_modules/google-spreadsheet/node_modules/google-auth-library/build/src/auth/googleauth.js:17:0 找不到模块:无法解析“child_process”
波纹管是我所拥有的导致错误的原因。
// The error appears when I do this import
import { GoogleSpreadsheet } from "google-spreadsheet";
const SPREADSHEET_ID = process.env.NEXT_PUBLIC_SPREADSHEET_ID;
const SHEET_ID = process.env.NEXT_PUBLIC_SHEET_ID;
const CLIENT_EMAIL = process.env.NEXT_PUBLIC_GOOGLE_CLIENT_EMAIL;
const PRIVATE_KEY = process.env.NEXT_PUBLIC_GOOGLE_SERVICE_PRIVATE_KEY;
const doc = new GoogleSpreadsheet(SPREADSHEET_ID);
const appendSpreadsheet = async (row) => {
try {
await doc.useServiceAccountAuth({
client_email: CLIENT_EMAIL,
private_key: PRIVATE_KEY,
});
// loads document properties and worksheets
await doc.loadInfo();
const sheet = doc.sheetsById[SHEET_ID];
const result = await sheet.addRow(row);
return result;
} …Run Code Online (Sandbox Code Playgroud) 我正在尝试将 Node-jsEncrypt 与 NextJS (tsx) 一起使用:
索引.tsx
import JSEncrypt from 'node-jsencrypt';
Run Code Online (Sandbox Code Playgroud)
包.json
"node-jsencrypt": "^1.0.0"
Run Code Online (Sandbox Code Playgroud)
日志
错误 - ./node_modules/node-jsencrypt/index.js:2:0
找不到模块:无法解析“fs”
注意:我没有找到该'webpack.config.js'文件,正如我在某些主题中看到的那样。
我有一个非常简单的 NextJS 9.3.5 项目。目前,它有一个页面/用户和一个pages/api/users从本地 MongoDB 表中检索所有用户的页面
它使用“next dev”在本地构建良好但是,它在“next build”失败并出现ECONNREFUSED错误
页面/用户
import fetch from "node-fetch"
import Link from "next/link"
export async function getStaticProps({ params }) {
const res = await fetch(`http://${process.env.VERCEL_URL}/api/users`)
const users = await res.json()
return { props: { users } }
}
export default function Users({ users }) {
return (
<ul>
{users.map(user => (
<li key={user.id}>
<Link href="/user/[id]" as={`/user/${user._id}`}>
<a>{user.name}</a>
</Link>
</li>
))}
</ul>
);
}
Run Code Online (Sandbox Code Playgroud)
页面/api/用户
import mongoMiddleware from "../../lib/api/mongo-middleware";
import apiHandler from "../../lib/api/api-handler";
export …Run Code Online (Sandbox Code Playgroud) 我想在 api 路由文件中使用 fs 模块来执行一些文件系统操作,但是,我收到此错误:Module not found: Can't resolve 'fs'。我不仅无法在处理程序函数中使用 fs,而且还无法启动项目,因为 fs 错误阻止了这一点。
这就是我的文件的样子。
小路:pages/api/getSchema.js
内容:
const fs = require("fs");
export default function handler(req, res) {
const id = req.query.id;
if(id){
const schemas = require('../../pageSchemas/index.json');
res.end(JSON.stringify(schemas[id]));
}
}
Run Code Online (Sandbox Code Playgroud) 我在将 javascript 文件导入 vue.js 组件时遇到错误:
这是 /components 子文件夹的内容:
/startingV/src/components$ ls -lah
total 132K
drwxr-xr-x 2 marco marco 4,0K dic 26 11:22 .
drwxr-xr-x 5 marco marco 4,0K dic 26 09:32 ..
-rw-r--r-- 1 marco marco 441 nov 2 2016 Counter.vue
-rw-r--r-- 1 marco marco 441 dic 21 15:13 FormValidation.vue
-rw-r--r-- 1 marco marco 100K dic 26 10:38 js_plumbing.js
-rw-r--r-- 1 marco marco 9,3K dic 26 10:38 js_plumbing.wasm
-rw-r--r-- 1 marco marco 473 dic 26 11:14 Result.vue
Run Code Online (Sandbox Code Playgroud)
编译时:
Failed to compile. …Run Code Online (Sandbox Code Playgroud) next.js ×5
javascript ×3
reactjs ×3
module ×2
build ×1
emscripten ×1
filesystems ×1
hadoop-yarn ×1
mongodb ×1
node.js ×1
npm ×1
vue.js ×1
webassembly ×1
webpack ×1