openscad / openscad-playground

OpenSCAD Web Playground
https://ochafik.com/openscad2
Other
121 stars 36 forks source link

build fails under node 21 #24

Open rcarmo opened 7 months ago

rcarmo commented 7 months ago

I get an error message stating that the build configuration is broken. I have the following Node versions:

node -v
v21.7.3
npm -v
10.5.0

Log:

% npm run build                                                        

> openscad-playground@0.1.0 build
> NODE_ENV=production npx rollup --config openscad-worker.rollup.config.js && webpack --mode=production

(node:96287) 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)
[!] RollupError: Node tried to load your configuration file as CommonJS even though it is likely an ES module. To resolve this, change the extension of your configuration to ".mjs", set "type": "module" in your package.json file or pass the "--bundleConfigAsCjs" flag.

Original error: Cannot use import statement outside a module
https://rollupjs.org/command-line-interface/#bundleconfigascjs
/Users/rcarmo/Build/openscad-playground/openscad-worker.rollup.config.js:2
import typescript from 'rollup-plugin-typescript2';
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at internalCompileFunction (node:internal/vm:128:18)
    at wrapSafe (node:internal/modules/cjs/loader:1279:20)
    at Module._compile (node:internal/modules/cjs/loader:1331:27)
    at Module._extensions..js (node:internal/modules/cjs/loader:1426:10)
    at Module.load (node:internal/modules/cjs/loader:1205:32)
    at Module._load (node:internal/modules/cjs/loader:1021:12)
    at cjsLoader (node:internal/modules/esm/translators:366:17)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:315:7)
    at ModuleJob.run (node:internal/modules/esm/module_job:222:25)
    at async ModuleLoader.import (node:internal/modules/esm/loader:323:24)
  [cause] /Users/rcarmo/Build/openscad-playground/openscad-worker.rollup.config.js:2
  import typescript from 'rollup-plugin-typescript2';
  ^^^^^^

  SyntaxError: Cannot use import statement outside a module
      at internalCompileFunction (node:internal/vm:128:18)
      at wrapSafe (node:internal/modules/cjs/loader:1279:20)
      at Module._compile (node:internal/modules/cjs/loader:1331:27)
      at Module._extensions..js (node:internal/modules/cjs/loader:1426:10)
      at Module.load (node:internal/modules/cjs/loader:1205:32)
      at Module._load (node:internal/modules/cjs/loader:1021:12)
      at cjsLoader (node:internal/modules/esm/translators:366:17)
      at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:315:7)
      at ModuleJob.run (node:internal/modules/esm/module_job:222:25)
      at async ModuleLoader.import (node:internal/modules/esm/loader:323:24)
JaxTheWolf commented 6 months ago

I keep getting the same error, trying multiple versions of Node (21, 20, 18, haven't tried other). I was planning on dockerising this project for myself (and maybe my friends).

ochafik commented 6 months ago

Sorry just seeing this. Building thing successfully here (on Mac) w/ Node v22.2.0 (make public && npm run build)

JaxTheWolf commented 6 months ago
FROM node:18-alpine

RUN apk update
RUN apk add wget make bash git zip 

RUN mkdir /src

COPY src /src

WORKDIR /src

RUN make public
RUN npm run start:prod

This is my Dockerfile. I think I got all the dependencies right. Fails with the same error as above.

ochafik commented 6 months ago

@JaxTheWolf weird, that Dockerfile works for me, in the current main branch, just modified COPY . /src and ran docker build . from the repo root.

JaxTheWolf commented 6 months ago

@JaxTheWolf weird, that Dockerfile works for me, in the current main branch, just modified COPY . /src and ran docker build . from the repo root.

Hm, could you try running it in a Linux VM? I would try Mac OS, but that's a bit more hassle than it's worth :D

ochafik commented 6 months ago

Ah sorry i think my copy ‘.’ without cleaning first means it didn’t try and build everything from the container. Will try again shortly

Edit: it's not that, still works. I'll try on Linux when I get my hands on a box or VM (or will just setup some github workflows).

scouzi1966 commented 4 months ago

Error is a bit misleading. Try installing rollup-plugin-typescript2. "npm install rollup-plugin-typescript2". This worked for me on a fairly up to dat ubuntu.