osdevisnot/klap

Klap can't find typescript on init

splashsky opened this issue ยท 11 comments

Howdy! I'm trying to get going with Klap, but upon making a new, empty directory (mkdir klap) and trying to run the typescript init (or even the non-typescript init) I get this error.

๐ŸŒŠ /JS/klap $ npx klap init
internal/modules/cjs/loader.js:883
  throw err;
  ^

Error: Cannot find module 'typescript'
Require stack:
- /home/splash/.nvm/versions/node/v14.15.4/lib/node_modules/klap/dist/index.js
- /home/splash/.nvm/versions/node/v14.15.4/lib/node_modules/klap/cli.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)
    at Function.Module._load (internal/modules/cjs/loader.js:725:27)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Object.975034 (/home/splash/.nvm/versions/node/v14.15.4/lib/node_modules/klap/dist/index.js:723369:18)
    at __webpack_require__ (/home/splash/.nvm/versions/node/v14.15.4/lib/node_modules/klap/dist/index.js:723418:43)
    at Object.956237 (/home/splash/.nvm/versions/node/v14.15.4/lib/node_modules/klap/dist/index.js:607953:17)
    at __webpack_require__ (/home/splash/.nvm/versions/node/v14.15.4/lib/node_modules/klap/dist/index.js:723418:43)
    at Module.600669 (/home/splash/.nvm/versions/node/v14.15.4/lib/node_modules/klap/dist/index.js:694661:30)
    at __webpack_require__ (/home/splash/.nvm/versions/node/v14.15.4/lib/node_modules/klap/dist/index.js:723418:43) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/home/splash/.nvm/versions/node/v14.15.4/lib/node_modules/klap/dist/index.js',
    '/home/splash/.nvm/versions/node/v14.15.4/lib/node_modules/klap/cli.js'
  ]
}

Any advice to get this fixed?

Additionally, doing npm i klap first in my empty directory made no difference.

๐ŸŒŠ /JS/klap $ npx klap init ts
internal/modules/cjs/loader.js:883
  throw err;
  ^

Error: Cannot find module 'typescript'
Require stack:
- /JS/klap/node_modules/klap/dist/index.js
- /JS/klap/node_modules/klap/cli.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)
    at Function.Module._load (internal/modules/cjs/loader.js:725:27)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Object.975034 (/JS/klap/node_modules/klap/dist/index.js:723369:18)
    at __webpack_require__ (/JS/klap/node_modules/klap/dist/index.js:723418:43)
    at Object.956237 (/JS/klap/node_modules/klap/dist/index.js:607953:17)
    at __webpack_require__ (/JS/klap/node_modules/klap/dist/index.js:723418:43)
    at Module.600669 (/JS/klap/node_modules/klap/dist/index.js:694661:30)
    at __webpack_require__ (/JS/klap/node_modules/klap/dist/index.js:723418:43) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/JS/klap/node_modules/klap/dist/index.js',
    '/JS/klap/node_modules/klap/cli.js'
  ]
}

Do you have TypeScript installed?

Do you have TypeScript installed?

Haha, new to the JS ecosystem so I thought that dependency would be handled automatically, my bad.

npm i typescript fixed that error, but I'm greeted by a more cryptic error...

๐ŸŒŠ /JS/klap $ npx klap init ts
klap@6.1.1 - Initializing your package...
(node:19669) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'split' of undefined
    at writePackage (/JS/klap/node_modules/klap/dist/index.js:722842:19)
    at async init_init (/JS/klap/node_modules/klap/dist/index.js:722941:14)
    at async /JS/klap/node_modules/klap/cli.js:18:4
(Use `node --trace-warnings ...` to show where the warning was created)
(node:19669) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:19669) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Not sure this will affect my ability to use Klap.

I think The Jingsin's project path (full path) will help solve this problem.

๐Ÿ‘‹ @splashsky

Haha, new to the JS ecosystem so I thought that dependency would be handled automatically, my bad.

This dependency should be handled automatically for you. It's not an user error. I will work on fixing this.

npm i typescript fixed that error, but I'm greeted by a more cryptic error...

Do you happen to have a package.json file in the directory where you are issuing init command? If I am thinking this correctly, the code path in init is able to read your package.json but fails to read name property from that package.json

Ah, thank ya much! I have it working fine now, just working through some other issues in my repo that are probably unrelated to Klap. When I build my module, how would I flag Babel to fix things such as Missing class properties transform?

how would I flag Babel to fix things such as Missing class properties transform

The class property transform is at stage-3, which means it's not a finalized feature for Javascript. You can find more information about the process here

I am not going to support stage-3 features in klap at this time. My apologies, but you might need to find alternative if you wish to use bleeding edge language features.

I am not going to support stage-3 features in klap at this time. My apologies, but you might need to find alternative if you wish to use bleeding edge language features.

Understandable, but is there a way to get Babel plugins working with Klap? Would I install the plugin and throw it into the .babelrc so I can use those features?

The extensibility story for klap is intentionally limited. This tool tries to provides a zero dependency experience with tiny output size for distributing libraries to NPM.

The problem with throwing a new .babelrc is that it needs you to install that plugin in your project. For the plugin to work correctly, you would also need @babel/core as a dependency. At this point, klap is no different than very many wrappers around rollup.

Also, in future, I would like to move to esbuild as a base for klap. This however is not possible without breaking usage if you had .babelrc customizations.

I had looked into esbuild as well, and the only thing it's missing for my purposes is umd format support (which appears to have an open PR). Otherwise it's a fantastic option, and it would be cool to see it adopted more.

Thanks for your help anyway! ๐Ÿ˜„

๐ŸŽ‰ This issue has been resolved in version 6.1.3 ๐ŸŽ‰

The release is available on:

Your semantic-release bot ๐Ÿ“ฆ๐Ÿš€