当尝试从导出Typescript 的私有库导入组件时,我们收到以下错误消息:
Module parse failed: Unexpected token (82:7)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
|
| // Types
> export type {
Run Code Online (Sandbox Code Playgroud)
我该如何解决这个问题?我尝试在tsconfig文件中显式包含库节点模块:
"include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx",
"node_modules/@private-lib/*.*"
],
"exclude": [""]
Run Code Online (Sandbox Code Playgroud)
但不幸的是,没有效果。似乎可以更改next.js的webpack配置,但不幸的是,尝试插入 Typescript 加载器并不起作用:
module.exports = {
webpack: (config, options) => {
config.module.rules.push({
test: /\.(ts|js)x?$/,
use: [
options.defaultLoaders.babel,
{
loader: "ts-loader",
options: {
transpileOnly: true,
experimentalWatchApi: …
Run Code Online (Sandbox Code Playgroud) 我对 Next js 及其部署过程相当陌生。我最近将我的一个 React js 项目转换为 Next js,以便利用 Next js 提供的服务器端渲染功能。现在到了部署时间,我发现如果node_modules
服务器中没有该文件夹,下一个版本将无法部署。我在我的页面中使用getServerSideProps
并使用"build": "next build"
package.json 中的命令进行构建。问题是我的 node_modules 文件夹接近 300MB(.next
构建又增加了大约 10MB),我认为每次部署都伴随这么大的重量并不是最佳实践(我打算部署此构建的不同实例,因此 310MB)服务器中的 X 个实例)。我在这里做错了什么还是这是实现这一目标的唯一方法?我很感激任何答案。谢谢...
我确实在我的 nextjs 应用程序中使用了反冲力。但是,如果我接下来运行(在开发或生产中没有区别),我会收到以下错误消息:
重复的原子键“companyData”。这是生产中的致命错误。但如果由于热模块更换而发生此警告,则可以安全地忽略此警告。
这是我实现它的方式:
/src/stores/CompanyStore.js:
import { useSetRecoilState, useRecoilValue , atom } from 'recoil';
import config from '../../content/config.yml';
const companyData = atom({
key: 'companyData',
default: {...config.company},
});
export const useSetCompanyData = () => useSetRecoilState(companyData);
export const useCompanyData = () => useRecoilValue(companyData);
export default {
useSetCompanyData,
useCompanyData,
};
Run Code Online (Sandbox Code Playgroud)
我在某些组件中这样使用它:
我的组件.js
import React from 'react';
...
...
import {useCompanyData} from '../stores/CompanyStore';
const MyComponent = () => {
const classes = useStyles();
const companyData = useCompanyData();
const { summary: headline, description …
Run Code Online (Sandbox Code Playgroud) Next.js 最近进行了修改(在 v11.0.x 中),其类型定义如下:
在next-env.d.ts
(不可修改,在每次构建时重新生成):
/// <reference types="next" />
/// <reference types="next/types/global" />
/// <reference types="next/image-types/global" />
Run Code Online (Sandbox Code Playgroud)
在node_modules/next/image-types/global.d.ts
(不可修改,不想使用patch-package
)中:
declare module '*.svg' {
const content: any
export default content
}
Run Code Online (Sandbox Code Playgroud)
现在的问题是我正在使用@svgr/webpack
,因此我需要执行以下操作:
declare module '*.svg' {
const content: React.FC<React.SVGAttributes<SVGElement>>
export default content
}
Run Code Online (Sandbox Code Playgroud)
之前将此代码放置在index.d.ts
用于工作的资产文件夹中。但现在不行了,结果我被迫单独投射每个导入。有什么办法可以直接做到这一点吗?
我想在Amazon S3上托管我的 React 项目。
我正在开发它Next.js
。
文件夹树如下所示。
pages
|- auth
| |- index.tsx
|- (...)
|- index.tsx
Run Code Online (Sandbox Code Playgroud)
我做到了
next build && next export
Run Code Online (Sandbox Code Playgroud)
构建和导出后,我期望它
out
|- _next
|- auth
| |- index.html /* I want another index.html */
|- (...)
|- index.html
|- static
Run Code Online (Sandbox Code Playgroud)
但我明白了,
|- _next
|- auth.html /*I need /auth/index.html*/
|- (...)
|- index.html
|- static
Run Code Online (Sandbox Code Playgroud)
我怎样才能实现呢。
先感谢您。
我想将我的nextjs
项目构建为开发模式。
我试过喜欢它
包.json
{
...
"scripts": {
"dev": "next",
"build:dev": "set NODE_ENV=development & next build",
"build:prod": "set NODE_ENV=production & next build",
"start:dev": "set NODE_ENV=development & next start",
"start:prod": "set NODE_ENV=production & next start"
}
...
}
Run Code Online (Sandbox Code Playgroud)
下一个.config.js
module.exports = withSass({
env: {
baseUrl: process.env.NODE_ENV === "development" ? "devServerURL": "prodServerURL"
}
});
Run Code Online (Sandbox Code Playgroud)
但我无法实现我想要的。
所以,我尝试了一些改变。
包.json
"scripts": {
"dev": "next",
"build": "next build",
"start:dev": "set NODE_ENV=development & next start",
"start:prod": "set NODE_ENV=production & next start"
}
Run Code Online (Sandbox Code Playgroud)
但它也不起作用。
如何构建 …
每当我跑步yarn dev
或npm run dev
:
yarn run v1.22.10
warning ../../../../package.json: No license field
$ next dev
ready - started server on 0.0.0.0:3000, url: http://localhost:3000
info - Using webpack 5. Reason: no next.config.js https://nextjs.org/docs/messages/webpack5
event - compiled successfully
event - build page: /
wait - compiling...
error Command failed with signal "SIGSEGV".
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Run Code Online (Sandbox Code Playgroud)
package.json
:
yarn run v1.22.10
warning ../../../../package.json: No license field
$ next dev
ready - started server on …
Run Code Online (Sandbox Code Playgroud) 我正在使用 Discord.js 库创建一个 Discord 机器人。每当我向文本通道发送嵌入消息时,其宽度会随着不同的数据而不断变化。
const celestialObject = new MessageEmbed()
.setColor("#F0386B")
.setTitle(
res.data.name == res.data.englishName
? res.data.englishName
: `${res.data.englishName} (${res.data.name})`
)
.attachFiles(attachment)
.setThumbnail("attachment://logo.png")
.addFields(
{
name: "```Density```",
value: res.data.density.toFixed(2) + " g/cm^3",
inline: true,
},
{
name: "```Gravity```",
value: res.data.gravity + " m/s^2",
inline: true,
},
{
name: "```Moons```",
value: res.data.moons ? Object.keys(res.data.moons).length : 0,
inline: true,
},
{
name: "```Mass```",
value: `
${res.data.mass.massValue.toFixed(2)}^
${res.data.mass.massExponent} kgs
`,
inline: true,
},
{
name: "```Escape Velocity```",
value: (res.data.escape / 1000).toFixed(1) + " …
Run Code Online (Sandbox Code Playgroud) 我有一个用 Node.js 构建的 Express Web 服务器。当我运行服务器时,最终我在终端中收到以下错误:
(node:196569) Warning: An error event has already been emitted on the socket. Please use the destroy method on the socket while handling a 'clientError' event.
(Use `node --trace-warnings ...` to show where the warning was created)
Run Code Online (Sandbox Code Playgroud)
我正在使用 node:https 创建服务器,如下所示:
const express = require('express');
const https = require('node:https');
// setting up express
const app = express();
// Setting up SSL Certificates
const https_options = {
key: process.env.HUTCHYBOP_KEY.replace(/\\n/g, '\n'),
cert: process.env.CRT_CODE.replace(/\\n/g, '\n'),
keepAlive: false
};
... …
Run Code Online (Sandbox Code Playgroud) const {
DEVELOPMENT_SERVER,
PRODUCTION_BUILD
} = require("next/constants");
require('dotenv').config()
const path = require('path')
const Dotenv = require('dotenv-webpack')
const nextConfig = {
webpack: config => ({ ...config, node: { fs: "empty" } })
};
module.exports = phase => {
if (phase === DEVELOPMENT_SERVER || phase === PRODUCTION_BUILD) {
const withCSS = require("@zeit/next-css");
return withCSS(nextConfig);
}
return nextConfig;
};
*module.exports = {
webpack: (config) => {
config.plugins = config.plugins || []
config.plugins = [
...config.plugins,
// Read the .env file
new Dotenv({
path: …
Run Code Online (Sandbox Code Playgroud)next.js ×8
reactjs ×5
node.js ×2
typescript ×2
webpack ×2
api ×1
apollo ×1
discord ×1
discord.js ×1
express ×1
https ×1
javascript ×1
nextjs-image ×1
npm ×1
package.json ×1
recoiljs ×1
webpack-4 ×1
yarnpkg ×1