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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Klap can't find typescript on init #198

Closed
splashsky opened this issue Mar 12, 2021 · 11 comments
Closed

Klap can't find typescript on init #198

splashsky opened this issue Mar 12, 2021 · 11 comments
Labels

Comments

@splashsky
Copy link

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?

@splashsky
Copy link
Author

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'
  ]
}

@fro9-dev
Copy link

Do you have TypeScript installed?

@splashsky
Copy link
Author

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.

@fro9-dev
Copy link

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

@osdevisnot
Copy link
Owner

馃憢 @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

osdevisnot added a commit that referenced this issue Mar 12, 2021
fix missing name from existing package.json with missing name property

re #198
@splashsky
Copy link
Author

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?

@osdevisnot
Copy link
Owner

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.

@splashsky
Copy link
Author

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?

@osdevisnot
Copy link
Owner

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.

@splashsky
Copy link
Author

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! 馃槃

osdevisnot added a commit that referenced this issue Mar 12, 2021
klap needs typescript as a dependency for types and usets flags but not for init. this release fixes
where typescript was incorrectly required during init

fix #198
@osdevisnot
Copy link
Owner

馃帀 This issue has been resolved in version 6.1.3 馃帀

The release is available on:

Your semantic-release bot 馃摝馃殌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants