Document tsconfig File for Plop Usage in TS

See original GitHub issue

How to reproduce

  1. yarn install plop
  2. Create a perfectly valid plopfile.ts:

import { NodePlopAPI, AddActionConfig } from 'plop';

export default function generator(plop: NodePlopAPI): void {
  ...
}
  1. yarn run plop

Expected behavior

plop prints a user prompt, generates files

Actual behavior

$ plop
/src/plopfile.ts:1
import { NodePlopAPI, AddActionConfig } from 'plop';
^^^^^^

SyntaxError: Cannot use import statement outside a module

Versions

Node version: 12.3.0 Plop version: 2.5.3

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:6
  • Comments:29 (16 by maintainers)

github_iconTop GitHub Comments

30reactions
Vanuancommented, Dec 18, 2019

Renamed to plopfile.js and removes TS syntax.

12reactions
danielfigueiredocommented, Mar 15, 2022

I followed all instructions here and also what is in the example FDiskas linked but I keep getting the same error no matter what Even if I run plop via ts-node which should be able to parse ts files I get this same error. My entire monorepo project only has TS packages and no JS at all, unfortunately, plop isn’t there yet to work well with TS and even after tossing a few hours on it, I couldn’t get it to work, so declaring bankruptcy on getting plopfile.ts to work.

[PLOP] Something went wrong with reading your plop file TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for /Users/dan/Projects/design-system/plopfile.ts
    at new NodeError (node:internal/errors:370:5)
    at Loader.defaultGetFormat [as _getFormat] (node:internal/modules/esm/get_format:71:15)
    at Loader.getFormat (node:internal/modules/esm/loader:105:42)
    at Loader.getModuleJob (node:internal/modules/esm/loader:243:31)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async Loader.import (node:internal/modules/esm/loader:177:17)
    at async nodePlop (file:///Users/dan/Projects/design-system/node_modules/node-plop/src/node-plop.js:198:26)
    at async Liftoff.run (file:///Users/dan/Projects/design-system/node_modules/plop/src/plop.js:56:12) {
  code: 'ERR_UNKNOWN_FILE_EXTENSION'
}

☝️ this error keeps being thrown no matter what I’ve added the "module": "commonjs" config to my tsconfig.json Using latest plop version "plop": "^3.0.5", and also using latest "ts-node": "^10.7.0",

🤷

Either way, I just wanted to say that this lib is great regardless so thanks for maintaining it

Read more comments on GitHub >

github_iconTop Results From Across the Web

Learning to Plop
A little tool that saves you time and helps your team build new files with consistency. Generate code when you want, how you...
Read more >
TSConfig Reference - Docs on every TSConfig option
"tsc.ts". ] } This is useful when you only have a small number of files and don't need to use a glob to...
Read more >
pages/hooks on your code with PlopJS. - DEV Community ‍ ‍
The following example is to generate automatically components. If you want to create hook you need to create new folders and files as...
Read more >
Boost your coding productivity with Plop: Tutorial - Medium
How to use Plop to generate custom React boilerplate. ... The templates are simply handlebars files (*.hbs) which, at their most basic level ......
Read more >
plop-react-ts - npm
Start using plop-react-ts in your project by running `npm i plop-react-ts`. ... useRedux: false, // use Redux files by default.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found