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

ES Module #381

Open
42zeroo opened this issue Mar 16, 2023 · 6 comments
Open

ES Module #381

42zeroo opened this issue Mar 16, 2023 · 6 comments

Comments

@42zeroo
Copy link

42zeroo commented Mar 16, 2023

Is there way to import and use this package as ES Module, not as CJS?

Whenever I'm trying to run my view from the browser, the error is thrown, which occurs when using tsc to compile:

Error [ERR_REQUIRE_ESM]: require() of ES Module C:\PROJEKTY\nodejsterminal\node_modules\tsx\dist\loader.js from C:\PROJEKTY\nodejsterminal\node_modules\express\lib\view.js not supported.
Instead change the require of loader.js in C:\PROJEKTY\nodejsterminal\node_modules\express\lib\view.js to a dynamic import() which is available in all CommonJS modules.
    at new View (C:\PROJEKTY\nodejsterminal\node_modules\express\lib\view.js:81:14)
    at Function.render (C:\PROJEKTY\nodejsterminal\node_modules\express\lib\application.js:587:12)
    at ServerResponse.render (C:\PROJEKTY\nodejsterminal\node_modules\express\lib\response.js:1039:7)
    at file:///C:/PROJEKTY/nodejsterminal/dist/utils/services/PreviewService.js:30:17
    at Layer.handle [as handle_request] (C:\PROJEKTY\nodejsterminal\node_modules\express\lib\router\layer.js:95:5)
    at next (C:\PROJEKTY\nodejsterminal\node_modules\express\lib\router\route.js:144:13)
    at Route.dispatch (C:\PROJEKTY\nodejsterminal\node_modules\express\lib\router\route.js:114:3)
    at Layer.handle [as handle_request] (C:\PROJEKTY\nodejsterminal\node_modules\express\lib\router\layer.js:95:5)
    at C:\PROJEKTY\nodejsterminal\node_modules\express\lib\router\index.js:284:15
    at Function.process_params (C:\PROJEKTY\nodejsterminal\node_modules\express\lib\router\index.js:346:12)
    at next (C:\PROJEKTY\nodejsterminal\node_modules\express\lib\router\index.js:280:10)
    at SendStream.error (C:\PROJEKTY\nodejsterminal\node_modules\serve-static\index.js:121:7)
    at SendStream.emit (node:events:526:28)
    at SendStream.error (C:\PROJEKTY\nodejsterminal\node_modules\send\index.js:270:17)
    at SendStream.onStatError (C:\PROJEKTY\nodejsterminal\node_modules\send\index.js:417:12)
    at next (C:\PROJEKTY\nodejsterminal\node_modules\send\index.js:731:16)
    at onstat (C:\PROJEKTY\nodejsterminal\node_modules\send\index.js:720:14)
    at FSReqCallback.oncomplete (node:fs:198:21)

When I have tried with tsx, another error is thrown, but again comming from express/lib/view.js:

c:\PROJEKTY\nodejsterminal\node_modules\express\lib\view.js:84
      throw new Error('Module "' + mod + '" does not provide a view engine.')
            ^

Error: Module "tsx" does not provide a view engine.
    at null.View (c:\PROJEKTY\nodejsterminal\node_modules\express\lib\view.js:84:13)
    at Function.render (c:\PROJEKTY\nodejsterminal\node_modules\express\lib\application.js:587:12)
    at ServerResponse.render (c:\PROJEKTY\nodejsterminal\node_modules\express\lib\response.js:1039:7)
    at null.<anonymous> (c:\PROJEKTY\nodejsterminal\src\utils\services\PreviewService.ts:38:11)
    at Layer.handle (c:\PROJEKTY\nodejsterminal\node_modules\express\lib\router\layer.js:95:5)
    at null.next (c:\PROJEKTY\nodejsterminal\node_modules\express\lib\router\route.js:144:13)
    at Route.dispatch (c:\PROJEKTY\nodejsterminal\node_modules\express\lib\router\route.js:114:3)
    at Layer.handle (c:\PROJEKTY\nodejsterminal\node_modules\express\lib\router\layer.js:95:5)
    at null.<anonymous> (c:\PROJEKTY\nodejsterminal\node_modules\express\lib\router\index.js:284:15)
    at Function.process_params (c:\PROJEKTY\nodejsterminal\node_modules\express\lib\router\index.js:346:12)
@ceddybi
Copy link

ceddybi commented Sep 25, 2023

@42zeroo where you able to fix this?

@Surdok
Copy link

Surdok commented Nov 5, 2023

Did somebody fix this issue..

@ceddybi
Copy link

ceddybi commented Nov 5, 2023

@Surdok i just used new nextjs with app router, it can export static html.

@Surdok
Copy link

Surdok commented Nov 5, 2023

@ceddybi
Can you elaborate more? Can I use nextjs to render from express? because in my case, I need to render .tsx files from express.
Also I am planning to not render static html..

@ceddybi
Copy link

ceddybi commented Nov 5, 2023

@Surdok Yes it's possible, with nextjs. you can render tsx and serve nextjs's app/api
as an express server.

or you can also set up a separate express server that communicates to nextjs.

@danielbayley80
Copy link

I was having this issue with this and a few other packages. I switched to TSX and haven't looked back.

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

4 participants