openscad-playground icon indicating copy to clipboard operation
openscad-playground copied to clipboard

build fails under node 21

Open rcarmo opened this issue 1 year ago • 7 comments

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                                                        

> [email protected] 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)

rcarmo avatar Apr 28 '24 19:04 rcarmo

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).

JaxTheWolf avatar May 30 '24 15:05 JaxTheWolf

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

ochafik avatar May 30 '24 15:05 ochafik

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.

JaxTheWolf avatar May 30 '24 16:05 JaxTheWolf

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

ochafik avatar May 30 '24 16:05 ochafik

@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

JaxTheWolf avatar May 30 '24 17:05 JaxTheWolf

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).

ochafik avatar May 30 '24 18:05 ochafik

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.

scouzi1966 avatar Jul 12 '24 18:07 scouzi1966