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

Pnpm dev crash: TS2354: This syntax requires an imported helper but module 'tslib' cannot be found. #1727

Closed
kuon opened this issue Aug 20, 2024 · 14 comments

Comments

@kuon
Copy link

kuon commented Aug 20, 2024

I am not sure if this is a typebot issue, but I open this issue to document this and give a workaround.

For some reason I wasn't able to pinpoint, I started hitting and issue where pnpm dev would crash with:

[!] (plugin typescript) RollupError: @rollup/plugin-typescript TS2354: This syntax requires an imported helper but module 'tslib' cannot be found.

I searched a bit and I was unable to find a definitive explanation to this issue.

But in case you encounter it, my fix was to change importHelper to false in the following file:

"importHelpers": true

change to:

    "importHelpers": false
@baptisteArno
Copy link
Owner

baptisteArno commented Aug 21, 2024

Good to know, thanks, I don't remember why this was enabled though, I just removed it and it built without error so I'll push this

@kuon
Copy link
Author

kuon commented Aug 21, 2024

Actually it started crashing again.

@typebot.io/nextjs:dev: /home/kuon/memoways/typebot.io/node_modules/.pnpm/rollup@3.26.2/node_modules/rollup/dist/shared/watch-cli.js:549
@typebot.io/nextjs:dev:     error.name = `Uncaught ${error.name}`;
@typebot.io/nextjs:dev:                ^
@typebot.io/nextjs:dev: 
@typebot.io/nextjs:dev: TypeError: Cannot assign to read only property 'name' of object 'RollupError: @rollup/plugin-typescript TS2354: This syntax requires an imported helper but module 'tslib' cannot be found.'
@typebot.io/nextjs:dev:     at process.closeWithError (/home/kuon/memoways/typebot.io/node_modules/.pnpm/rollup@3.26.2/node_modules/rollup/dist/shared/watch-cli.js:549:16)
@typebot.io/nextjs:dev:     at process.emit (node:events:520:28)
@typebot.io/nextjs:dev:     at process.emit (/home/kuon/memoways/typebot.io/node_modules/.pnpm/source-map-support@0.5.21/node_modules/source-map-support/source-map-support.js:516:21)
@typebot.io/nextjs:dev:     at SignalExit.#processEmit (/home/kuon/memoways/typebot.io/node_modules/.pnpm/rollup@3.26.2/node_modules/rollup/dist/shared/watch-cli.js:344:23)
@typebot.io/nextjs:dev:     at process.#process.emit (/home/kuon/memoways/typebot.io/node_modules/.pnpm/rollup@3.26.2/node_modules/rollup/dist/shared/watch-cli.js:288:37)
@typebot.io/nextjs:dev:     at process._fatalException (node:internal/process/execution:191:25)
@typebot.io/nextjs:dev: 
@typebot.io/nextjs:dev: Node.js v22.6.0
@typebot.io/nextjs:dev:  ELIFECYCLE  Command failed with exit code 7.
@typebot.io/nextjs:dev: ERROR: command finished with error: command (/home/kuon/memoways/typebot.io/packages/embeds/nextjs) /usr/bin/pnpm run dev exited (7)
@typebot.io/react:dev: /home/kuon/memoways/typebot.io/node_modules/.pnpm/rollup@3.26.2/node_modules/rollup/dist/shared/watch-cli.js:549
@typebot.io/react:dev:     error.name = `Uncaught ${error.name}`;
@typebot.io/react:dev:                ^
@typebot.io/react:dev: 
@typebot.io/react:dev: TypeError: Cannot assign to read only property 'name' of object 'RollupError: @rollup/plugin-typescript TS2354: This syntax requires an imported helper but module 'tslib' cannot be found.'
@typebot.io/react:dev:     at process.closeWithError (/home/kuon/memoways/typebot.io/node_modules/.pnpm/rollup@3.26.2/node_modules/rollup/dist/shared/watch-cli.js:549:16)
@typebot.io/react:dev:     at process.emit (node:events:520:28)
@typebot.io/react:dev:     at process.emit (/home/kuon/memoways/typebot.io/node_modules/.pnpm/source-map-support@0.5.21/node_modules/source-map-support/source-map-support.js:516:21)
@typebot.io/react:dev:     at SignalExit.#processEmit (/home/kuon/memoways/typebot.io/node_modules/.pnpm/rollup@3.26.2/node_modules/rollup/dist/shared/watch-cli.js:344:23)
@typebot.io/react:dev:     at process.#process.emit (/home/kuon/memoways/typebot.io/node_modules/.pnpm/rollup@3.26.2/node_modules/rollup/dist/shared/watch-cli.js:288:37)
@typebot.io/react:dev:     at process._fatalException (node:internal/process/execution:191:25)
@typebot.io/react:dev: 
@typebot.io/react:dev: Node.js v22.6.0
@typebot.io/react:dev:  ELIFECYCLE  Command failed with exit code 7.

Slight variation after commenting that line in watch-cli.js:549:

@typebot.io/nextjs:dev: [!] (plugin typescript) RollupError: @rollup/plugin-typescript TS2354: This syntax requires an imported helper but module 'tslib' cannot be found.
@typebot.io/nextjs:dev: ../../forge/blocks/openid/actions/login.ts (24:13)
@typebot.io/nextjs:dev: 
@typebot.io/nextjs:dev:  24     server: async ({
@typebot.io/nextjs:dev:                 ~~~~~~~~
@typebot.io/nextjs:dev:  25       credentials,
@typebot.io/nextjs:dev:     ~~~~~~~~~~~~~~~~~~
@typebot.io/nextjs:dev: ... 
@typebot.io/nextjs:dev:  27       variables,
@typebot.io/nextjs:dev:     ~~~~~~~~~~~~~~~~
@typebot.io/nextjs:dev:  28     }) => {
@typebot.io/nextjs:dev:     ~~~~~~~~~~~
@typebot.io/nextjs:dev: 
@typebot.io/nextjs:dev:     at error (/home/kuon/memoways/typebot.io/node_modules/.pnpm/rollup@3.26.2/node_modules/rollup/dist/shared/rollup.js:349:30)
@typebot.io/nextjs:dev:     at Object.error (/home/kuon/memoways/typebot.io/node_modules/.pnpm/rollup@3.26.2/node_modules/rollup/dist/shared/rollup.js:1715:20)
@typebot.io/nextjs:dev:     at emitDiagnostic (file:///home/kuon/memoways/typebot.io/node_modules/.pnpm/@rollup+plugin-typescript@11.1.2_rollup@3.26.2_tslib@2.6.0_typescript@5.4.5/node_modules/@rollup/plugin-typescript/dist/es/index.js:521:17)
@typebot.io/nextjs:dev:     at reportDiagnostics (file:///home/kuon/memoways/typebot.io/node_modules/.pnpm/@rollup+plugin-typescript@11.1.2_rollup@3.26.2_tslib@2.6.0_typescript@5.4.5/node_modules/@rollup/plugin-typescript/dist/es/index.js:529:9)
@typebot.io/nextjs:dev:     at Array.forEach (<anonymous>)
@typebot.io/nextjs:dev:     at emitFilesAndReportErrors (/home/kuon/memoways/typebot.io/node_modules/.pnpm/typescript@5.4.5/node_modules/typescript/lib/typescript.js:127124:17)
@typebot.io/nextjs:dev:     at Object.result.afterProgramCreate (/home/kuon/memoways/typebot.io/node_modules/.pnpm/typescript@5.4.5/node_modules/typescript/lib/typescript.js:127283:7)
@typebot.io/nextjs:dev:     at Object.afterProgramCreate (file:///home/kuon/memoways/typebot.io/node_modules/.pnpm/@rollup+plugin-typescript@11.1.2_rollup@3.26.2_tslib@2.6.0_typescript@5.4.5/node_modules/@rollup/plugin-typescript/dist/es/index.js:686:29)
@typebot.io/nextjs:dev:     at synchronizeProgram (/home/kuon/memoways/typebot.io/node_modules/.pnpm/typescript@5.4.5/node_modules/typescript/lib/typescript.js:127652:14)
@typebot.io/nextjs:dev:     at updateProgram (/home/kuon/memoways/typebot.io/node_modules/.pnpm/typescript@5.4.5/node_modules/typescript/lib/typescript.js:127848:11)
@typebot.io/nextjs:dev:     at Timeout.updateProgramWithWatchStatus [as _onTimeout] (/home/kuon/memoways/typebot.io/node_modules/.pnpm/typescript@5.4.5/node_modules/typescript/lib/typescript.js:127833:7)
@typebot.io/nextjs:dev:     at listOnTimeout (node:internal/timers:583:11)
@typebot.io/nextjs:dev:     at processTimers (node:internal/timers:519:7)
@typebot.io/nextjs:dev: 
@typebot.io/nextjs:dev: 

@kuon
Copy link
Author

kuon commented Aug 21, 2024

I don't know what changed, but now when there is an error in my code, the whole pnpm dev process dies, but before it would just print the error and let me correct it before recompiling.

I can reproduce this 100%.

I found a few references:

@baptisteArno baptisteArno reopened this Aug 22, 2024
@baptisteArno
Copy link
Owner

Can't reproduce, but I may be stumble upon this issue once and added importHelpers for that reason.

Can you try to delete node_modules folders and dist folders and install and build again?

@kuon
Copy link
Author

kuon commented Aug 22, 2024

I did a git clean to remove everything and I also removed ~/.local/share/pnpm and ~/.cache/pnpm

but the issue persists.

my pnpm version

{
  'typebot-os': '2.27.0',
  npm: '10.8.2',
  node: '22.6.0',
  acorn: '8.11.3',
  ada: '2.9.0',
  amaro: '0.0.6',
  ares: '1.29.0',
  brotli: '1.1.0',
  cjs_module_lexer: '1.2.2',
  cldr: '45.0',
  icu: '75.1',
  llhttp: '9.2.1',
  modules: '127',
  napi: '9',
  nbytes: '0.1.0',
  ncrypto: '0.0.1',
  nghttp2: '1.62.1',
  openssl: '3.3.1',
  simdjson: '3.9.4',
  simdutf: '5.3.0',
  sqlite: '3.46.0',
  tz: '2024a',
  undici: '6.19.2',
  unicode: '15.1',
  uv: '1.48.0',
  uvwasi: '0.0.21',
  v8: '12.4.254.21-node.18',
  zlib: '1.3.1'
}

After cleaning the message is slightly different (I mispelled console on purpose to generate an error.

viewer:dev: (node:1660734) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
viewer:dev: (Use `node --trace-deprecation ...` to show where the warning was created)
viewer:dev: Something went wrong ReferenceError: consoe is not defined
viewer:dev:     at Object.server (webpack-internal:///(api)/../../packages/forge/blocks/openid/actions/login.ts:38:13)
viewer:dev:     ... 13 lines matching cause stack trace ...
viewer:dev:     at async callRecursive (file:///home/kuon/memoways/typebot.io/node_modules/.pnpm/@trpc+server@10.40.0/node_modules/@trpc/server/dist/index.mjs:456:32) {
viewer:dev:   code: 'INTERNAL_SERVER_ERROR',
viewer:dev:   name: 'TRPCError',
viewer:dev:   [cause]: ReferenceError: consoe is not defined
viewer:dev:       at Object.server (webpack-internal:///(api)/../../packages/forge/blocks/openid/actions/login.ts:38:13)
viewer:dev:       at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
viewer:dev:       at async executeForgedBlock (webpack-internal:///(api)/../../packages/bot-engine/forge/executeForgedBlock.ts:111:5)
viewer:dev:       at async eval (webpack-internal:///(api)/../../packages/bot-engine/executeIntegration.ts:67:24)
viewer:dev:       at async executeGroup (webpack-internal:///(api)/../../packages/bot-engine/executeGroup.ts:100:319)
viewer:dev:       at async startSession (webpack-internal:///(api)/../../packages/bot-engine/startSession.ts:120:21)
viewer:dev:       at async startChat (webpack-internal:///(api)/../../packages/bot-engine/apiHandlers/startChat.ts:21:142)
viewer:dev:       at async eval (webpack-internal:///(api)/./src/features/chat/api/startChat.ts:21:41)
viewer:dev:       at async resolveMiddleware (file:///home/kuon/memoways/typebot.io/node_modules/.pnpm/@trpc+server@10.40.0/node_modules/@trpc/server/dist/index.mjs:420:30)
viewer:dev:       at async callRecursive (file:///home/kuon/memoways/typebot.io/node_modules/.pnpm/@trpc+server@10.40.0/node_modules/@trpc/server/dist/index.mjs:456:32)
viewer:dev:       at async outputMiddleware (file:///home/kuon/memoways/typebot.io/node_modules/.pnpm/@trpc+server@10.40.0/node_modules/@trpc/server/dist/index.mjs:301:24)
viewer:dev:       at async callRecursive (file:///home/kuon/memoways/typebot.io/node_modules/.pnpm/@trpc+server@10.40.0/node_modules/@trpc/server/dist/index.mjs:456:32)
viewer:dev:       at async callRecursive (file:///home/kuon/memoways/typebot.io/node_modules/.pnpm/@trpc+server@10.40.0/node_modules/@trpc/server/dist/index.mjs:456:32)
viewer:dev:       at async callRecursive (file:///home/kuon/memoways/typebot.io/node_modules/.pnpm/@trpc+server@10.40.0/node_modules/@trpc/server/dist/index.mjs:456:32)
viewer:dev:       at async callRecursive (file:///home/kuon/memoways/typebot.io/node_modules/.pnpm/@trpc+server@10.40.0/node_modules/@trpc/server/dist/index.mjs:456:32)
viewer:dev: }
@typebot.io/nextjs:dev: /home/kuon/memoways/typebot.io/node_modules/.pnpm/rollup@3.26.2/node_modules/rollup/dist/shared/watch-cli.js:549
@typebot.io/nextjs:dev:     error.name = `Uncaught ${error.name}`;
@typebot.io/nextjs:dev:                ^
@typebot.io/nextjs:dev: 
@typebot.io/nextjs:dev: TypeError: Cannot assign to read only property 'name' of object 'RollupError: @rollup/plugin-typescript TS2354: This syntax requires an imported helper but module 'tslib' cannot be found.'
@typebot.io/nextjs:dev:     at process.closeWithError (/home/kuon/memoways/typebot.io/node_modules/.pnpm/rollup@3.26.2/node_modules/rollup/dist/shared/watch-cli.js:549:16)
@typebot.io/nextjs:dev:     at process.emit (node:events:520:28)
@typebot.io/nextjs:dev:     at process.emit (/home/kuon/memoways/typebot.io/node_modules/.pnpm/source-map-support@0.5.21/node_modules/source-map-support/source-map-support.js:516:21)
@typebot.io/nextjs:dev:     at SignalExit.#processEmit (/home/kuon/memoways/typebot.io/node_modules/.pnpm/rollup@3.26.2/node_modules/rollup/dist/shared/watch-cli.js:344:23)
@typebot.io/nextjs:dev:     at process.#process.emit (/home/kuon/memoways/typebot.io/node_modules/.pnpm/rollup@3.26.2/node_modules/rollup/dist/shared/watch-cli.js:288:37)
@typebot.io/nextjs:dev:     at process._fatalException (node:internal/process/execution:191:25)
@typebot.io/nextjs:dev: 
@typebot.io/nextjs:dev: Node.js v22.6.0
@typebot.io/nextjs:dev:  ELIFECYCLE  Command failed with exit code 7.
@typebot.io/nextjs:dev: ERROR: command finished with error: command (/home/kuon/memoways/typebot.io/packages/embeds/nextjs) /usr/bin/pnpm run dev exited (7)
@typebot.io/react:dev: /home/kuon/memoways/typebot.io/node_modules/.pnpm/rollup@3.26.2/node_modules/rollup/dist/shared/watch-cli.js:549
@typebot.io/react:dev:     error.name = `Uncaught ${error.name}`;
@typebot.io/react:dev:                ^
@typebot.io/react:dev: 
@typebot.io/react:dev: TypeError: Cannot assign to read only property 'name' of object 'RollupError: @rollup/plugin-typescript TS2354: This syntax requires an imported helper but module 'tslib' cannot be found.'
@typebot.io/react:dev:     at process.closeWithError (/home/kuon/memoways/typebot.io/node_modules/.pnpm/rollup@3.26.2/node_modules/rollup/dist/shared/watch-cli.js:549:16)
@typebot.io/react:dev:     at process.emit (node:events:520:28)
@typebot.io/react:dev:     at process.emit (/home/kuon/memoways/typebot.io/node_modules/.pnpm/source-map-support@0.5.21/node_modules/source-map-support/source-map-support.js:516:21)
@typebot.io/react:dev:     at SignalExit.#processEmit (/home/kuon/memoways/typebot.io/node_modules/.pnpm/rollup@3.26.2/node_modules/rollup/dist/shared/watch-cli.js:344:23)
@typebot.io/react:dev:     at process.#process.emit (/home/kuon/memoways/typebot.io/node_modules/.pnpm/rollup@3.26.2/node_modules/rollup/dist/shared/watch-cli.js:288:37)
@typebot.io/react:dev:     at process._fatalException (node:internal/process/execution:191:25)
@typebot.io/react:dev: 
@typebot.io/react:dev: Node.js v22.6.0
@typebot.io/react:dev:  ELIFECYCLE  Command failed with exit code 7.
@typebot.io/js:dev: /home/kuon/memoways/typebot.io/node_modules/.pnpm/rollup@3.26.2/node_modules/rollup/dist/shared/watch-cli.js:549
@typebot.io/js:dev:     error.name = `Uncaught ${error.name}`;
@typebot.io/js:dev:                ^
@typebot.io/js:dev: 
@typebot.io/js:dev: TypeError: Cannot assign to read only property 'name' of object 'RollupError: @rollup/plugin-typescript TS2552: Cannot find name 'consoe'. Did you mean 'console'?'
@typebot.io/js:dev:     at process.closeWithError (/home/kuon/memoways/typebot.io/node_modules/.pnpm/rollup@3.26.2/node_modules/rollup/dist/shared/watch-cli.js:549:16)
@typebot.io/js:dev:     at process.emit (node:events:520:28)
@typebot.io/js:dev:     at process.emit (/home/kuon/memoways/typebot.io/node_modules/.pnpm/source-map-support@0.5.21/node_modules/source-map-support/source-map-support.js:516:21)
@typebot.io/js:dev:     at SignalExit.#processEmit (/home/kuon/memoways/typebot.io/node_modules/.pnpm/rollup@3.26.2/node_modules/rollup/dist/shared/watch-cli.js:344:23)
@typebot.io/js:dev:     at process.#process.emit (/home/kuon/memoways/typebot.io/node_modules/.pnpm/rollup@3.26.2/node_modules/rollup/dist/shared/watch-cli.js:288:37)
@typebot.io/js:dev:     at process._fatalException (node:internal/process/execution:191:25)
@typebot.io/js:dev: 
@typebot.io/js:dev: Node.js v22.6.0
@typebot.io/nextjs#dev: command (/home/kuon/memoways/typebot.io/packages/embeds/nextjs) /usr/bin/pnpm run dev exited (7)

 Tasks:    2 successful, 10 total
Cached:    0 cached, 10 total
  Time:    15.919s 
Failed:    @typebot.io/nextjs#dev

 ERROR  run failed: command  exited (7)
 ELIFECYCLE  Command failed with exit code 7.

@baptisteArno
Copy link
Owner

This is not the same error, it's an issue with your code here

@kuon
Copy link
Author

kuon commented Aug 22, 2024

This is not the same error, it's an issue with your code here

Yes, but that's the whole point. When there is an error in my code, reporting this error crashes rollup and pnpm dev.

When developing forge plugin, the app automatically reloads when the code change, but now when there is a typo in the code, the whole pnpm dev process crash.

@baptisteArno
Copy link
Owner

Got it. that comes from "noEmitOnError": true. I added it recently because we could basically build the app with an error.

I'll see if I can disable this when running dev

@kuon
Copy link
Author

kuon commented Aug 22, 2024

Ok I was able to fix the tslib issue.

    "tslib": "2.6.0"

Must be added to the package.json of the forge package (as a dependency, not dev dependency as tslib is a runtime library) and "importHelpers": true must be added to the tsconfig.json of the forge package.

Now that this is fixed, changing noEmitOnError does fix the pnpm dev process crashing.

So it is actually two separate issues that got mixed. One issue is that noEmitOnError changed, and this made me realize the other issue which is that tslib is a runtime dependency and should be added to the dependencies of the packages requiring it and NOT devDependency (first line of the README https://github.com/Microsoft/tslib).

@kuon
Copy link
Author

kuon commented Aug 22, 2024

So the fix for the tslib issue is to modify the create-new-block script to add:

"importHelpers": true

below this line

jsxImportSource: 'react',

and

dependencies: { "tslib": "2.6.0"}

below this one:

license: 'AGPL-3.0-or-later',

I guess the rest of the uses of tslib in the rest of typebot should also move it to dependencies but honestly I am not sure. I don't use typescript on a daily basic and this is all new to me.

@baptisteArno
Copy link
Owner

baptisteArno commented Aug 22, 2024

I'm not sure about this to be honest we don't import tslib

@baptisteArno
Copy link
Owner

Please let me know how I can reproduce the error

@kuon
Copy link
Author

kuon commented Aug 22, 2024

Ok I did more tests, and I can no longer reproduce it 100%. It does happens sometimes but not always. It seems to depend on the order which viewer:dev, nextjs:dev and react:dev appears in the logs, but I am not sure as the logs are widely different when it occurs vs when it does not occur.

But I can confirm that my proposed fix is not actually a fix, it just happened to work at the right time. And I guess that's why I thought the first fix was also a fix. I guess I was unlucky because I tried about 10 times and it seemed to work, but now, with more load on my dev server with other tasks, it is happening a lot less.

I suggest we close this and keep it for reference if it happens again. I am sorry for taking so much of your time with this.

@kuon kuon closed this as completed Aug 22, 2024
@baptisteArno
Copy link
Owner

No worries, it helps a lot, you create good issues 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Deployed 🎉
Development

No branches or pull requests

2 participants