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
Add a comment  | 

1 Answer 1

Reset to default 0

NODE_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)

本文标签: