admin管理员组文章数量:1122832
I'm writing the TypeScript simplest modules to learn some of the basics of the language, therefore I need TO NOT store (4500 file items within 140MB space) • to at least 100 exercises. To be fair, these modules be related to Obsidian app Plugin API, hence TypeScript and the transpiler esbuild are needed.
package.json file contents:
{
"name": "oppa01",
"main": "oppa01.ts",
"version": "0.0.1",
"type": "module",
"scripts": {
"version": "zsh version.sh",
"manual": "esbuild ${name}.ts --bundle --outfile=${name}.js",
"build": "tsc -noEmit -skipLibCheck && node esbuild.config.mjs production",
"watch": "node esbuild.config.mjs",
"run": "node ${name}.js"
},
"keywords": [],
"author": "canic",
"license": "MIT",
"devDependencies": {
"@types/node": "^16.11.6",
"@typescript-eslint/eslint-plugin": "5.29.0",
"@typescript-eslint/parser": "5.29.0",
"builtin-modules": "3.3.0",
"esbuild": "0.17.3",
"tslib": "2.4.0",
"typescript": "^4.7.4"
}
}
esbuild.config.mjs contents:
import { esbuild } from 'esbuild';
import { process } from 'process';
import { builtins } from 'builtin-modules';
const banner =
`/*
THIS IS A GENERATED / BUNDLED FILE BY ESBUILD
to view the source, please visit the github repository containing the TypeScript file for 'oppa01 exercise'
*/
`;
const prod = (process.argv[2] === "production");
const context = await esbuild.context ({
banner: {
js: banner,
},
entryPoints: ["oppa01.ts"],
bundle: true,
external: [
"electron",
"@codemirror/autocomplete",
"@codemirror/collab",
"@codemirror/commands",
"@codemirror/language",
"@codemirror/lint",
"@codemirror/search",
"@codemirror/state",
"@codemirror/view",
"@lezer/common",
"@lezer/highlight",
"@lezer/lr",
...builtins],
format: "cjs",
target: "es2018",
logLevel: "info",
sourcemap: prod ? false : "inline",
treeShaking: true,
outfile: "oppa01.js",
minify: false,
});
if (prod) {
await context.rebuild ();
process.exit (0);
} else {
await context.watch ();
}
The GitHub repo:
I have tried subpath aliases:
{
"name": "oppa01",
"main": "oppa01.ts",
"version": "0.0.1",
"imports": {
"#*": "/usr/local/share/node/node_modules/*"
},
...
}
import { esbuild } from '#/esbuild';
import { process } from '#/process';
import { builtins } from '#/builtin-modules';
Also, require file text inclusion:
// esbuild.config.mjs
import { createRequire } from "module";
const require = createRequire(import.meta.url);
...
Also, --experimental-specifier-resolution=node
flag with explicit using and with file name alongside its suffix defining:
import { esbuild } from '#/esbuild/lib/main.js';
Also, absolute path specifying:
// cp -R "$HOME/.nvm/versions/node/v20.18.0/lib/node_modules" /usr/local/share/node
import { esbuild } from '/usr/local/share/node/node_modules/esbuild/lib/main.js';
And also TypeScript compiler typeRoot specifying:
{
"compilerOptions": {
"typeRoots": ["/usr/local/share/node/node_modules"]
...
}
}
I'm writing the TypeScript simplest modules to learn some of the basics of the language, therefore I need TO NOT store (4500 file items within 140MB space) • to at least 100 exercises. To be fair, these modules be related to Obsidian app Plugin API, hence TypeScript and the transpiler esbuild are needed.
package.json file contents:
{
"name": "oppa01",
"main": "oppa01.ts",
"version": "0.0.1",
"type": "module",
"scripts": {
"version": "zsh version.sh",
"manual": "esbuild ${name}.ts --bundle --outfile=${name}.js",
"build": "tsc -noEmit -skipLibCheck && node esbuild.config.mjs production",
"watch": "node esbuild.config.mjs",
"run": "node ${name}.js"
},
"keywords": [],
"author": "canic",
"license": "MIT",
"devDependencies": {
"@types/node": "^16.11.6",
"@typescript-eslint/eslint-plugin": "5.29.0",
"@typescript-eslint/parser": "5.29.0",
"builtin-modules": "3.3.0",
"esbuild": "0.17.3",
"tslib": "2.4.0",
"typescript": "^4.7.4"
}
}
esbuild.config.mjs contents:
import { esbuild } from 'esbuild';
import { process } from 'process';
import { builtins } from 'builtin-modules';
const banner =
`/*
THIS IS A GENERATED / BUNDLED FILE BY ESBUILD
to view the source, please visit the github repository containing the TypeScript file for 'oppa01 exercise'
*/
`;
const prod = (process.argv[2] === "production");
const context = await esbuild.context ({
banner: {
js: banner,
},
entryPoints: ["oppa01.ts"],
bundle: true,
external: [
"electron",
"@codemirror/autocomplete",
"@codemirror/collab",
"@codemirror/commands",
"@codemirror/language",
"@codemirror/lint",
"@codemirror/search",
"@codemirror/state",
"@codemirror/view",
"@lezer/common",
"@lezer/highlight",
"@lezer/lr",
...builtins],
format: "cjs",
target: "es2018",
logLevel: "info",
sourcemap: prod ? false : "inline",
treeShaking: true,
outfile: "oppa01.js",
minify: false,
});
if (prod) {
await context.rebuild ();
process.exit (0);
} else {
await context.watch ();
}
The GitHub repo: https://github.com/delayedFromSoft/nodeESBuild
I have tried subpath aliases:
{
"name": "oppa01",
"main": "oppa01.ts",
"version": "0.0.1",
"imports": {
"#*": "/usr/local/share/node/node_modules/*"
},
...
}
import { esbuild } from '#/esbuild';
import { process } from '#/process';
import { builtins } from '#/builtin-modules';
Also, require file text inclusion:
// esbuild.config.mjs
import { createRequire } from "module";
const require = createRequire(import.meta.url);
...
Also, --experimental-specifier-resolution=node
flag with explicit using and with file name alongside its suffix defining:
import { esbuild } from '#/esbuild/lib/main.js';
Also, absolute path specifying:
// cp -R "$HOME/.nvm/versions/node/v20.18.0/lib/node_modules" /usr/local/share/node
import { esbuild } from '/usr/local/share/node/node_modules/esbuild/lib/main.js';
And also TypeScript compiler typeRoot specifying:
{
"compilerOptions": {
"typeRoots": ["/usr/local/share/node/node_modules"]
...
}
}
Share
Improve this question
asked Nov 25, 2024 at 18:05
cnamecname
214 bronze badges
1 Answer
Reset to default 0NODE_PATH
environment variable causes:
cp -r "$HOME/.nvm/versions/node/v20.18.0/lib/node_modules" $HOME; mv $HOME/node_modules $HOME/.node_modules
npm run build
> Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'esbuild' imported from /Users/abc/Documents/Source/prog/nodejs/typescript/oppa01/esbuild.config.mjs
Did you mean to import "file:///Users/abc/.node_modules/esbuild/lib/main.js"?
Its direct setting still errorneous:
export NODE_PATH=$HOME/.node_modules; npm run build
< ..The same error log here..
Only these absolute path declarations alongside modules names are worked, that's must ban some developers from NodeJS.org as well:
// esbuild.config.mjs
import esbuild from 'file:///Users/abc/.node_modules/esbuild/lib/main.js';
import process from 'process';
import builtins from 'file:///Users/abc/.node_modules/builtin-modules/index.js';
...
export NODE_PATH=""; npm run build
< (node:50499) ExperimentalWarning: Importing JSON modules is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
本文标签:
版权声明:本文标题:typescript - Is there any of way of avoid creating of the Node.js developing package local repository cache containing @types an 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736298628a1930263.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论