Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to use in Nest.js #379

Closed
chuteany opened this issue Feb 7, 2024 · 5 comments
Closed

Unable to use in Nest.js #379

chuteany opened this issue Feb 7, 2024 · 5 comments
Projects

Comments

@chuteany
Copy link

chuteany commented Feb 7, 2024

  1. create node in MathNode.ts
    import { defineNode, NodeInterface } from "@baklavajs/core"; import { NumberInterface, SelectInterface } from "@baklavajs/renderer-vue"; export default defineNode({ type: "Math", inputs: { number1: () => new NumberInterface("Number", 1), number2: () => new NumberInterface("Number", 10), operation: () => new SelectInterface("Operation", "Add", ["Add", "Subtract"]).setPort(false), }, outputs: { output: () => new NodeInterface("Output", 0), }, calculate({ number1, number2, operation }) { let output: number; if (operation === "Add") { output = Number(number1) + Number(number2); } else if (operation === "Subtract") { output = Number(number1) - Number(number2); } else { throw new Error(Unknown operation: ${operation}); } return new Promise((resolve, reject) => { setTimeout(() => { resolve({ output }) ; }, 3000); }) }, });

  2. import this file
    import MathNode from "./MathNode";

  3. register this node
    const editor = new Editor(); editor.registerNodeType(MathNode, { category: "A-Base" });
    4.Then, the console reported an error.
    require() of ES Module .\node_modules.pnpm@baklavajs+renderer-vue@2.3.0\node_modules@baklavajs\renderer-vue\dist\renderer-vust\renderer-vue.umd.js from .\dist\modules\auth\MathNode.js not supported.
    renderer-vue.umd.js is treated as an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which declares all .js files in that package that package scope as ES modules.
    Instead either rename renderer-vue.umd.js to end in .cjs, change the requiring code to use dynamic import() which is available in all CommonJS modules, or change "type": "moduletype": "module" to "type": "commonjs" in D:\Programs\SDMS\eims-task\node_modules.pnpm@baklavajs+renderer-vue@2.3.0\node_modules@baklavajs\renderer-vue\package.jll .js files ason to treat all .js files as CommonJS (using .mjs for all ES modules instead).

@starker-xp
Copy link
Contributor

Do you have "type": "module" in your package.json ?

@chuteany
Copy link
Author

chuteany commented Feb 8, 2024

The original configuration of the project is "type": "module". I want to use it in both browser and Node.js environments simultaneously. I cannot change it to "type": "commonjs".

@chuteany
Copy link
Author

chuteany commented Feb 8, 2024

I modified the original configuration as follows, so it can be used simultaneously in both browser and Node.js environments.

  1. in package.json
    "type": "module", "main": "./dist/renderer-vue.cjs", "module": "./dist/renderer-vue.es.js", "exports": { ".": { "import": "./dist/renderer-vue.es.js", "require": "./dist/renderer-vue.cjs" } }

  2. in vite.config.js

lib: { ... formats: ["umd", "es", "cjs"], },

@chuteany
Copy link
Author

chuteany commented Feb 8, 2024

Could you do this Pull Request

@newcat newcat added this to Done but not released in V2 Feb 8, 2024
@newcat
Copy link
Owner

newcat commented Feb 8, 2024

Fixed in v2.4.0

@newcat newcat closed this as completed Feb 8, 2024
@newcat newcat moved this from Done but not released to Done in V2 Feb 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
V2
  
Done
Development

No branches or pull requests

3 participants