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

failed to build locally #3

Closed
yunmc opened this issue May 30, 2022 · 14 comments
Closed

failed to build locally #3

yunmc opened this issue May 30, 2022 · 14 comments

Comments

@yunmc
Copy link

yunmc commented May 30, 2022

// unified-latex-util-parse

  • npm install
  • npm run build

../unified-latex-util-match/dist/index.d.ts:3:1127 - error TS2307: Cannot find module '../unified-latex-types/dist' or its corresponding type declarations.

3 export declare const anyEnvironment: (node: any) => node is import("../unified-latex-types/dist").Environment, anyMacro: (node: any) => node is import("../unified-latex-types/dist").Macro, anyString: (node: any) => node is import("../unified-latex-types/dist").String, argument: (node: any) => node is import("../unified-latex-types/dist").Argument, blankArgument: (node: any) => boolean, comment: (node: any) => node is import("../unified-latex-types/dist").Comment, environment: (node: any, envName?: string | undefined) => node is import("../unified-latex-types/dist").Environment, group: (node: any) => node is import("../unified-latex-types/dist").Group, macro: (node: any, macroName?: string | undefined) => node is import("../unified-latex-types/dist").Macro, math: (node: any) => node is import("../unified-latex-types/dist").InlineMath | import("../unified-latex-types/dist").DisplayMath, parbreak: (node: any) => node is import("../unified-latex-types/dist").Parbreak, string: (node: any, value?: string | undefined) => node is import("../unified-latex-types/dist").String, whitespace: (node: any) => node is import("../unified-latex-types/dist").Whitespace;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

@siefkenj
Copy link
Owner

Are you running build from the root directory or from the unified-latex-util-parse directory?

@yunmc
Copy link
Author

yunmc commented May 31, 2022

Are you running build from the root directory or from the unified-latex-util-parse directory?

Thanks for ur reply, from the /packages/unified-latex-util-parse directory.

@siefkenj
Copy link
Owner

Try building from the root directory.

@yunmc
Copy link
Author

yunmc commented Jun 1, 2022

Try building from the root directory.

it's ok, but index.d.ts is missing.

@siefkenj
Copy link
Owner

siefkenj commented Jun 1, 2022

Which index.d.ts is missing when building from the root directory? Building from the root directory should build everything...

@yunmc
Copy link
Author

yunmc commented Jun 2, 2022

/packages/unified-latex-util-parse

@yunmc
Copy link
Author

yunmc commented Jun 2, 2022

sth wrong with my env?

node - v14.15.4
npm - 6.14.10

@siefkenj
Copy link
Owner

siefkenj commented Jun 2, 2022

I am running node 16.14.2 and npm 8.5.1. You might need a newer version of npm for workspaces to work correctly. I believe workspaces were only introduced in npm v7.

@yunmc
Copy link
Author

yunmc commented Jun 6, 2022

I build succeeded through node 16!
But I have another problem, I cannot run my nodejs server with ESM module(unified-latex), maybe I need to prebuild *.ts with webpack or esbuild?

@siefkenj
Copy link
Owner

siefkenj commented Jun 6, 2022

You should be able to import the index.cjs file directly. That file is compiled for CommonJS

@yunmc
Copy link
Author

yunmc commented Jun 7, 2022

const latexParser = require('unified-latex/packages/unified-latex-util-parse/dist/index.cjs');

tsconfig.json:
"esModuleInterop": true

/node_modules/unified/index.js:1
export {unified} from './lib/index.js'
^^^^^^

SyntaxError: Unexpected token export
at Module._compile (internal/modules/cjs/loader.js:723:23)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Module.require (internal/modules/cjs/loader.js:692:17)
at require (internal/modules/cjs/helpers.js:25:18)
at Object. (/Users/yunmingchun/Project/content-server-node/node_modules/unified-latex/packages/unified-latex-util-parse/libs/plugin-from-string.ts:1:41)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Module.require (internal/modules/cjs/loader.js:692:17)
at require (internal/modules/cjs/helpers.js:25:18)
at Object. (/Users/yunmingchun/Project/content-server-node/app/controller/open/other.ts:8:21)

@siefkenj
Copy link
Owner

siefkenj commented Jun 7, 2022

Are you using Typescript? If so, you should be importing the es module, not the CommonJS one. Also, your import statement looks weird. Relative imports start with ./, so yours is an absolute import. I'm not sure how it's working at all.

You can try using npm link in the dist directory and your local directory. Then you can do require("unified-latex-util-parse")

@yunmc
Copy link
Author

yunmc commented Jun 8, 2022

I found eggjs do not support ESM... thx!~

@siefkenj
Copy link
Owner

siefkenj commented Jun 8, 2022

Great. I'm glad it got resolved!

@siefkenj siefkenj closed this as completed Jun 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants