luwes / sinuous

🧬 Light, fast, reactive UI library
https://sinuous.netlify.app
1.04k stars 34 forks source link

Make sinuous a type:module #233

Closed canadaduane closed 1 year ago

canadaduane commented 1 year ago

Currently, sinuous cannot be loaded as an ES module in node:

https://github.com/canadaduane/sinuous-as-node-module

Run npm install; npm run start:

> sinuous-as-module@1.0.0 start /home/duane/tmp/html
> node index.js

(node:374662) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
(Use `node --trace-warnings ...` to show where the warning was created)
/home/duane/tmp/html/node_modules/.pnpm/sinuous@0.30.0/node_modules/sinuous/src/index.js:5
import {
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at internalCompileFunction (node:internal/vm:73:18)
    at wrapSafe (node:internal/modules/cjs/loader:1175:20)
    at Module._compile (node:internal/modules/cjs/loader:1219:27)
    at Module._extensions..js (node:internal/modules/cjs/loader:1309:10)
    at Module.load (node:internal/modules/cjs/loader:1113:32)
    at Module._load (node:internal/modules/cjs/loader:960:12)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:165:29)
    at ModuleJob.run (node:internal/modules/esm/module_job:192:25)
    at async DefaultModuleLoader.import (node:internal/modules/esm/loader:246:24)
    at async file:///home/duane/tmp/html/index.js:1:18

Node.js v20.3.0

I believe all that is needed is to add "type": "module" to the sinuous package.json file. When I test this locally, it resolves the issue.

The ability to run this as a module would be very helpful in creating a pure JS server (no build step).

luwes commented 1 year ago

thanks for the feedback, I'll look at this soon. feel free to open a PR