Error loading custom node (tempModule[nodeName] is not a constructor)

Describe the issue/error/question

I have a custom node that I’ve created with n8n-node-dev, the node compiles just fine but when I start n8n I get an error message.

What is the error message (if any)?

Error loading node "PDF" from: "/home/user/.n8n/custom/PDF.node.js" - tempModule[nodeName] is not a constructor
 ›   Error: There was an error: tempModule[nodeName] is not a constructor

Please share the workflow

No workflow but here’s the node definition.

import { IExecuteFunctions } from 'n8n-core';
import { INodeExecutionData, INodeType, INodeTypeDescription } from 'n8n-workflow';

export class MPdf implements INodeType {
	description: INodeTypeDescription = {
		displayName: 'PDF Fill',
		name: 'pdf',
		group: ['transform'],
		version: 1,
		description: 'Fills input PDF based on the JSON payload.',
		defaults: {
			name: 'PDF Fill',
			color: '#772244',
		},
		inputs: ['main', 'main'],
		outputs: ['main'],
		properties: [
			{
				displayName: 'My String',
				name: 'myString',
				type: 'string',
				default: '',
				placeholder: 'Placeholder value',
				description: 'The description text',
			},
		],
	};

	async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
		const items = this.getInputData(0);
		const pdf = this.getInputData(1);

		console.log(items, pdf)

		let item: INodeExecutionData;

		for (let itemIndex = 0; itemIndex < items.length; itemIndex++) {
			item = items[itemIndex];

			const payload = JSON.parse(item.json['fields'] as string);

			Object.entries(payload).forEach(
				([key, value]) => console.log(key, value)
			);

			item = items[itemIndex];
		}

		return this.prepareOutputData(items);
	}
}

Share the output returned by the last node

Information on your n8n setup

  • n8n version: 0.189.1
  • Database you’re using (default: SQLite): SQLite
  • Running n8n with the execution process [own(default), main]: default
  • Running n8n via [Docker, npm, n8n.cloud, desktop app]: npm

Hi sne,
it looks to me like n8n cannot resolve the node name correctly. Could you try setting the classname and description name like this.

export class PdfFill implements INodeType {
	description: INodeTypeDescription = {
		displayName: 'PDF Fill',
		name: 'pdfFill',
	}
}
1 Like

Hi marcus,

I tried changing the classname and description but unfortunately I’m getting the same error as before. Any other ideas? Thanks

Hey @sne,
i tried to reproduce your problem but wasn’t really able to. Instead of using the n8n-nodes-dev approach you could follow this tutorial about building a node based on using our n8n-nodes-starter repo.

I also did a free online webinar yesterday about Learn how to build your own nodes. You can rewatch the stream on Youtube or Twitch.

2 Likes

Hi @marcus

I compared my node to the starter node that you posted and the issue was with naming of the class and n8n being unable to resolve it. After some refactoring I got the problem sorted out.

Thanks for your support!

1 Like

Hey sne, glad to hear you could fix it. Thanks for confirming.

I was the same problem. it was a file named wrong.
but don’t forget to delete the /dist folder and update npm link or the problem error will stay