Skip to content

Commit 63bdf6d

Browse files
fix: resolve node class loading issues
- Fixed package.json structure following n8n-nodes-starter pattern - Changed export default to named export for CountryStateCity class - Added proper index.ts and index.js entry points - Updated dependencies and peer dependencies - Fixed country-state-city imports to use CommonJS require - Added proper n8n configuration with credentials array - Node now loads successfully without 'Class could not be found' error
1 parent 45ae718 commit 63bdf6d

6 files changed

Lines changed: 24 additions & 11 deletions

File tree

index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require('./dist/index.js');

index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './nodes/CountryStateCity/CountryStateCity.node';
3.48 KB
Binary file not shown.

nodes/CountryStateCity/CountryStateCity.node.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@ import {
55
INodeTypeDescription,
66
IDataObject,
77
} from 'n8n-workflow';
8-
import { ICountry, IState, ICity } from 'country-state-city';
9-
import Country from 'country-state-city/lib/country';
10-
import State from 'country-state-city/lib/state';
11-
import City from 'country-state-city/lib/city';
128

13-
export default class CountryStateCity implements INodeType {
9+
// Importações compatíveis com CommonJS
10+
const { Country, State, City } = require('country-state-city');
11+
12+
export class CountryStateCity implements INodeType {
1413
description: INodeTypeDescription = {
1514
displayName: 'Country State City',
1615
name: 'countryStateCity',
@@ -87,7 +86,7 @@ export default class CountryStateCity implements INodeType {
8786
const countryCode = this.getNodeParameter('countryCode', itemIndex, '') as string;
8887
const stateCode = this.getNodeParameter('stateCode', itemIndex, '') as string;
8988

90-
let result: ICountry | IState[] | ICity[] | undefined | null = null;
89+
let result: any = null;
9190

9291
if (operation === 'getCountryByCode') {
9392
result = Country.getCountryByCode(countryCode);

package.json

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"version": "0.1.0",
44
"description": "n8n node for country-state-city",
55
"license": "MIT",
6+
"homepage": "https://docs.n8n.io/integrations/community-nodes/",
67
"author": {
78
"name": "Andre Kutianski"
89
},
@@ -16,31 +17,41 @@
1617
"state",
1718
"city"
1819
],
20+
"engines": {
21+
"node": ">=18.10",
22+
"pnpm": ">=8.6"
23+
},
24+
"packageManager": "pnpm@8.6.2",
1925
"main": "index.js",
2026
"scripts": {
2127
"build": "tsc",
2228
"dev": "tsc --watch",
23-
"format": "prettier --write nodes credentials"
29+
"format": "prettier --write nodes credentials",
30+
"lint": "tslint -p tsconfig.json -c tslint.json",
31+
"lintfix": "tslint --fix -p tsconfig.json -c tslint.json",
32+
"prepublishOnly": "npm run build"
2433
},
2534
"files": [
2635
"dist"
2736
],
2837
"n8n": {
2938
"n8nNodesApiVersion": 1,
39+
"credentials": [],
3040
"nodes": [
3141
"dist/nodes/CountryStateCity/CountryStateCity.node.js"
3242
]
3343
},
3444
"devDependencies": {
35-
"@types/express": "^4.17.6",
36-
"@types/node": "^14.18.45",
37-
"@typescript-eslint/parser": "~5.45",
45+
"@types/node": "^20.8.10",
3846
"gulp": "^4.0.2",
39-
"n8n-core": "*",
4047
"n8n-workflow": "*",
4148
"prettier": "^2.7.1",
49+
"tslint": "^6.1.2",
4250
"typescript": "~5.0.4"
4351
},
52+
"peerDependencies": {
53+
"n8n-workflow": "*"
54+
},
4455
"dependencies": {
4556
"country-state-city": "^3.1.2"
4657
}

tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"sourceMap": true
1414
},
1515
"include": [
16+
"index.ts",
1617
"nodes/**/*.ts",
1718
"credentials/**/*.ts"
1819
],

0 commit comments

Comments
 (0)