Open offeex opened 10 months ago
Hey, I am getting the same error. When I import all from 'json-as-xlsx'
I can actually see that the exported xlsx
property is undefined
.
Hi, not sure why this is happenning, last build was a day ago and this issue was reported 3 days ago, if anyone has an idea/PR I can happily merge
https://www.npmjs.com/package/json-as-xlsx?activeTab=versions
I also tried with a demo project
{
"name": "json-text",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "npx ts-node index.ts"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"json-as-xlsx": "^2.5.5"
},
"devDependencies": {
"@types/node": "^20.8.7"
}
}
{
"compilerOptions": {
"types": ["node"],
"moduleResolution": "node",
"target": "es2018"
}
}
import xlsx, { IJsonSheet } from "json-as-xlsx";
import { writeFileSync } from "fs";
const products = [
{
name: "John Doe",
email: "john.doe@example.com",
phone: "+1234567890",
city: "New York",
company_type: "Software Development",
experience: "5 years",
portfolio: "www.johndoeportfolio.com",
price: "$5000",
opys_robit: "Web development, mobile applications, UI/UX design",
},
{
name: "Jane Smith",
email: "jane.smith@example.com",
phone: "+0987654321",
city: "Los Angeles",
company_type: "Graphic Design",
experience: "3 years",
portfolio: "www.janesmithdesigns.com",
price: "$4000",
opys_robit: "Logo design, branding, print design",
},
];
const data: IJsonSheet[] = [
{
sheet: "BazaDizainerov-Kyiv-15-50",
columns: [
{ label: "name", value: "name" },
{ label: "email", value: "email" },
{ label: "phone", value: "phone" },
{ label: "city", value: "city" },
{ label: "company_type", value: "company_type" },
{ label: "experience", value: "experience" },
{ label: "portfolio", value: "portfolio" },
{ label: "price", value: "price" },
{ label: "opys_robit", value: "opys_robit" },
],
content: products,
},
];
writeFileSync("data.xlsx", xlsx(data));
this is also the error than I am getting
json-text ☭ nr start
> json-text@1.0.0 start
> npx ts-node index.ts
/Users/XXX/Projects/json-text/index.ts:47
writeFileSync("data.xlsx", xlsx(data));
^
TypeError: (0 , json_as_xlsx_1.default) is not a function
at Object.<anonymous> (/Users/XXX/Projects/json-text/index.ts:47:32)
at Module._compile (node:internal/modules/cjs/loader:1103:14)
at Module.m._compile (/Users/XXX/.npm/_npx/1bf7c3c15bf47d04/node_modules/ts-node/src/index.ts:1618:23)
at Module._extensions..js (node:internal/modules/cjs/loader:1157:10)
at Object.require.extensions.<computed> [as .ts] (/Users/XXX/.npm/_npx/1bf7c3c15bf47d04/node_modules/ts-node/src/index.ts:1621:12)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
at phase4 (/Users/XXX/.npm/_npx/1bf7c3c15bf47d04/node_modules/ts-node/src/bin.ts:649:14)
at bootstrap (/Users/XXX/.npm/_npx/1bf7c3c15bf47d04/node_modules/ts-node/src/bin.ts:95:10)
json-text ☭
i was getting same error solved it by using require instead of import like this
// eslint-disable-next-line @typescript-eslint/no-var-requires const xlsx = require('json-as-xlsx');
Here's what i get: