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

Plop is not able to read a a plopfile written in typescript #360

Closed
blascsi opened this issue Oct 14, 2022 · 3 comments
Closed

Plop is not able to read a a plopfile written in typescript #360

blascsi opened this issue Oct 14, 2022 · 3 comments

Comments

@blascsi
Copy link

blascsi commented Oct 14, 2022

I've been trying to include Plop in one of my projects without much luck in the past few days. Today I realised that downgrading Plop to the major version 2 seems to handle this case correctly but upgrading it to version 3 breaks it again. I'm not aware of this being deprecated (please feel free to close this if it was) so I thought opening a ticket could be helpful.
The error I'm getting while running plop with a plopfile.ts:

$ npm run plop

> [email protected] plop
> plop

[PLOP] Something went wrong with reading your plop file TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts"
    at new NodeError (node:internal/errors:371:5)
    at Object.file: (node:internal/modules/esm/get_format:72:15)
    at defaultGetFormat (node:internal/modules/esm/get_format:85:38)
    at defaultLoad (node:internal/modules/esm/load:13:42)
    at ESMLoader.load (node:internal/modules/esm/loader:303:26)
    at ESMLoader.moduleProvider (node:internal/modules/esm/loader:230:58)
    at new ModuleJob (node:internal/modules/esm/module_job:63:26)
    at ESMLoader.getModuleJob (node:internal/modules/esm/loader:244:11)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async Promise.all (index 0) {
  code: 'ERR_UNKNOWN_FILE_EXTENSION'
}

A minimal repro repo created to show the issue:
https://github.com/blascsi/plop-3-typescript-error

The plop version that I found handled this case correctly: "^2.7.6

I tried following an implementation from #290 to get this working, and found the version there.

@hs-ltbyce
Copy link

Hi, I have same this problem.
you can try use this version:

    "node-plop": "0.26.2",
    "plop": "2.7.4",

I use this version and it work

@crutchcorn
Copy link
Member

You'll need to compile the TS file before usage. We have an open ticket to use Plop TS config files without compiling it:

#297

@airtonix
Copy link

@crutchcorn then we should be removing any mention of plopfile.ts from production documentation.

plop/README.md

Line 148 in 973c1ce

// plopfile.ts

or at the very least:

🛑 ✋

plopfile.ts is not yet directly usable without first compiling it.

  "scripts": {
    "postinstall": "tsc ./plopfile.ts > ./plopfile.js"
  }

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

No branches or pull requests

4 participants