我想在npm脚本中引用我的包版本,以便在应用程序中显示当前版本.就像是
{
"name": "bla",
"version": "1.0.0",
"author": "bla bla",
"scripts": {
"build": "node VERSION=<<package.version>> build/build.js"
}
}
Run Code Online (Sandbox Code Playgroud)
有没有办法做到这一点?
我刚刚开始使用 eslint。我初始化了它并开始修复它指出的问题。然而,它不应该抱怨一个问题:
const data = fs.readFileSync(path.join(__dirname, _FILENAME));
Run Code Online (Sandbox Code Playgroud)
错误是:
error '__dirname' is not defined
Run Code Online (Sandbox Code Playgroud)
我做了一些搜索,发现当您添加到未定义的--experimental节点命令时。__dirname然而,对我来说情况并非如此。我没有使用该--experimental标志运行节点。
看看这些问题:
我正在创建一个项目并使用 nodejs,为后端表达。一切正常,但是当我对文件进行任何更改时,由于以下错误,nodemon 无法重新启动服务器:
Error: listen EADDRINUSE: address already in use :::5000
索引.js:
const express = require("express");
const morgan = require("morgan");
const mongoose = require("mongoose");
const cookieParser = require("cookie-parser");
const session = require("express-session");
const FileStore = require("session-file-store")(session);
const dotenv = require("dotenv");
var passport = require("passport");
dotenv.config();
const PORT = process.env.PORT || 5000;
const app = express();
.....
app.listen(PORT, () => console.log(`Server listening on port ${PORT}!`));
Run Code Online (Sandbox Code Playgroud)
包.json
const express = require("express");
const morgan = require("morgan");
const mongoose = require("mongoose");
const cookieParser = …Run Code Online (Sandbox Code Playgroud) 我正在尝试在 Ubuntu 18.04 上部署我的工作 Windows 10 Spring-Boot/React 应用程序,但尽管多次尝试修复,但仍然收到“react-scripts: Permission denied”错误。希望你们中的一位反应专家可以发现我做错了什么。
我的 package.json 看起来像这样
{
"name": "medaverter-front",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.3.2",
"@testing-library/user-event": "^7.1.2",
"axios": "^0.19.2",
"bootstrap": "^4.4.1",
"react": "^16.13.0",
"react-dom": "^16.13.0",
"react-router-dom": "^5.1.2",
"react-scripts": "3.4.0",
"react-table-6": "^6.11.0",
"react-validation": "^3.0.7",
"reactstrap": "^6.5.0",
"validator": "^12.2.0"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
], …Run Code Online (Sandbox Code Playgroud) 目前我正在使用"react": "17.0.2"并且已经安装"react-markdown": "^7.0.1"通过npm i react-markdown我正在使用这个包来显示我从 Strapi CMS 获取的富文本。我使用以下代码来显示内容:
import ReactMarkdown from "react-markdown";
export default function name({ posts }) {
return (
<>
<div>
<div>
{posts.Title}
</div>
</div>
<div>
<ReactMarkdown source={posts.Content} escapeHtml={false} />
</div>
</>
);
}
export async function getStaticProps() {
const res = await fetch("http://localhost:1337/blogs");
const posts = await res.json();
return {
props: { posts },
};
}
Run Code Online (Sandbox Code Playgroud)
但是当我运行它时,它给了我以下错误:
我正在使用节点v14.17.0并尝试添加"type": "module".
我的package.json:
import ReactMarkdown from "react-markdown";
export …Run Code Online (Sandbox Code Playgroud) 我正在使用 npm 作为构建生产 docker 映像的一部分。我想确保 package-lock.json 不会改变和匹配。
这个问题与这些有关。但是没有一个解决方案对我有用。
我可以安装一个没有问题的包,npm install @scope/package但是我不能用纱线做同样的事情:yarn add @scope/package
纱线抛出以下错误:
An unexpected error occurred: "https://npm.pkg.github.com/download/@scope/package/1.2.8/089b08cffb16074c210ec3a59b04de268ae1c7b3a0492dce110adee3ada05bdd: Request failed \"401 Unauthorized\"".
我的 .npmrc 文件看起来像这样:(在 .yarnrc 下尝试和不使用)
registry=https://registry.npmjs.org/
//npm.pkg.github.com/:_authToken=MY_AUTHTOKEN
@scope:registry=https://npm.pkg.github.com/
Run Code Online (Sandbox Code Playgroud)
我试过添加这个 .yarnrc 文件:
registry "https://registry.npmjs.org"
"@scope:registry" "https://npm.pkg.github.com"
Run Code Online (Sandbox Code Playgroud)
(没有 .yarnrc)我试过这个 .npmrc 文件
registry=https://registry.yarnpkg.com/
@scope:registry=https://npm.pkg.github.com
//npm.pkg.github.com/:_authToken=MY_AUTHTOKEN
always-auth=true
Run Code Online (Sandbox Code Playgroud)
MY_AUTHTOKEN我Personal Access Token从 Github 生成的我在哪里。(它可以访问包中的所有内容)
我试图:
npm login使用我的PAT作为密码yarn login万一出现任何混淆,我实际上并不是在尝试 @scope 和 /package,而是在尝试我的实际作用域和包名称。 …
新来反应,并且在使用纱线安装命令时遇到问题,出现以下错误:
Error: Cannot find module '/Users/MacPro/Desktop/Developer/React/.yarn/releases/yarn-berry.js'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:1029:15)
at Function.Module._load (internal/modules/cjs/loader.js:898:27)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
at internal/main/run_main_module.js:17:47 code:'MODULE_NOT_FOUND', requireStack: []
Run Code Online (Sandbox Code Playgroud)
任何与yarn 函数相关的内容都会返回此错误。已尝试通过自制程序卸载并重新安装,但总是导致这种情况。npm install -g yarn 表示它也已更新并安装。
有什么帮助吗?
而且,几周前它运行良好。
先感谢您。
我正在尝试使用两个参数在 ts-node-dev 之上为我的节点服务器运行脚本:--transpileOnly 和--ignoreWatch。但是我收到以下错误:
我的 package.json:
ps:我在 MacOS Catalina 上使用 brew 安装的纱线和节点。
当我尝试npm从 GitHub 操作安装我的模块时,我收到以下错误:
npm ERR! 401 Unauthorized - GET https://npm.pkg.github.com/@xxxx%2fxxxx-analytics - Your request could not be authenticated by the GitHub Packages service. Please ensure your access token is valid and has the appropriate scopes configured.
Run Code Online (Sandbox Code Playgroud)
在您发表评论之前,我已经使用范围和访问令牌正确配置了 .npmrc,并且在本地安装私有包时一切正常。
这是我的 GitHub 工作流程操作:
name: JavaScript workflow
on: [push]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Use Node.js 12.x
uses: actions/setup-node@v1
with:
node-version: '12.x'
- name: npmrc
run: cat .npmrc
- name: npm install
run: |
npm install
env: …Run Code Online (Sandbox Code Playgroud) npm ×7
yarnpkg ×5
node.js ×3
reactjs ×3
javascript ×2
eslint ×1
express ×1
github ×1
jenkins ×1
markdown ×1
nodemon ×1
npm-install ×1
npm-registry ×1
npm-scripts ×1
package.json ×1
registry ×1
strapi ×1
typescript ×1
zsh ×1