Cptble is not defined
Hello
I am having problems with this line of code, I can't see if the variable cptable is declared anywhere.
C:\Users\Simon\AppData\Roaming\npm\node_modules\xl-json\node_modules\xlsx\xlsx.js:9
if(typeof cptable === 'undefined') cptable = require('./dist/cpexcel');
^
ReferenceError: cptable is not defined
at C:\Users\Simon\AppData\Roaming\npm\node_modules\xl-json\node_modules\xlsx\xlsx.js:9:45
at Object.<anonymous> (C:\Users\Simon\AppData\Roaming\npm\node_modules\xl-json\node_modules\xlsx\xlsx.js:5389:3)
at Module._compile (module.js:425:26)
at Object.Module._extensions..js (module.js:432:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:313:12)
at Module.require (module.js:366:17)
at require (module.js:385:17)
at Object.<anonymous> (C:\Users\Simon\AppData\Roaming\npm\node_modules\xl-json\node_modules\j\j.js:4:12)
at Module._compile (module.js:425:26)
This problem is caused by script being running in scrict mode
How are you resolve this issue? I have same issue.
@loongdefect the codepage library is an optional dependency, mainly because it is big and is only needed for international support or reading older Excel files.
For support with direct script tag insertion, the variable cptable is a global. This library has logic to support codepage processing if the library is available and effectively skip the processing otherwise.
You are probably seeing the issue because you are in strict mode.
How me resolve this use strict?
Remove "use strict" in ./dist/cpexcel.js in line 805?
@loongdefect If you are requiring the xlsx module directly, check your code tree for "use strict". If you are using a module that requires xlsx, check to see if that module has "use strict".
Can you share the full error stack trace? That will show whether it's coming from your code or some other module
This error:
ERROR in ./~/xlsx/dist/cpexcel.js
Module not found: Error: Can't resolve './cptable' in 'E:\Work\Home\Bababibo\weberpforbuild\weberpforbuild_client\node_modules\xlsx\dist'
@ ./~/xlsx/dist/cpexcel.js 808:16-41
@ ./~/xlsx/xlsx.js
@ ./src/app/components/Users/contract/contract.component.ts
@ ./src/app/app.module.ts
@ ./src/main.ts
@ multi webpack-dev-server/client?http://localhost:4200/ ./src/main.ts
In component have code:
"use strict"
import { Component, Input, OnInit } from '@angular/core';
...
readExcel() {
if (typeof require !== 'undefined') {
var XLSX = require('xlsx');
var workbook = XLSX.readFile('test.xlsx');
}
}
I change code in file cpexcel and resolve:
function(root, factory) {
"use strict";
if(typeof cptable === "undefined") {
if(typeof require !== "undefined"){
//var cpt = require('./cpt' + 'able');
var cpt = require('./cpexcel.js');
if (typeof module !== 'undefined' && module.exports) module.exports = factory(cpt);
else root.cptable = factory(cpt);
} else throw new Error("cptable not found");
} else cptable = factory(cptable);
}
Hi @reviewher, This issue i had resolve. But other issue with filesystem. My project use angular-cli and angular developer had confirm can't use filesystem on frondent.
On Sat, Mar 4, 2017, 2:59 PM reviewher [email protected] wrote:
@loongdefect https://github.com/loongdefect If you are requiring the xlsx module directly, check your code tree for "use strict". If you are using a module that requires xlsx, check to see if that module has "use strict".
Can you share the full error stack trace? That will show whether it's coming from your code or some other module
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/SheetJS/js-xlsx/issues/324#issuecomment-284135637, or mute the thread https://github.com/notifications/unsubscribe-auth/AH3p8MC_wlsb3EjmsLvNaIoS2T7v-5WTks5riRnVgaJpZM4GowH- .
var workbook = XLSX.readFile('test.xlsx'); does not work on front end, you need to get the data in somehow and use XLSX.read
Has this been fixed? A lot of people is using strict mode everywhere to enforce best practices.
I started seeing this problem when I set the node v8 flag '--use_strict'
const v8 = require("v8");
v8.setFlagsFromString("--use_strict");
I was, however able to run with :
#!/usr/bin/env node
"use strict"; // as first line in script
xlsx:0.9.12
node:7.5.0
osx:10.10.5
@appersonj are you sure that strict mode is actually enforced if you put it in the shebang line?
This is still causing problems when using strict mode. I think it should be reopened
I resolve this issue by change code. It problem of require cptable in code.
On Fri, May 12, 2017, 6:57 PM Ramsés López [email protected] wrote:
This is causing problems when using strict mode. I think it should be reopened
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/SheetJS/js-xlsx/issues/324#issuecomment-301057739, or mute the thread https://github.com/notifications/unsubscribe-auth/AH3p8Po2Na7cjjiAER7jhl2CAfMd3oa-ks5r5Ek9gaJpZM4GowH- .
I was unable to trip the issue by forcing strict mode in chrome. I think the following changes to xlsx resolves the issue in nodejs:
- if(typeof cptable === 'undefined') cptable = require('./dist/cpexcel.js');
+ if(typeof cptable === 'undefined') global.cptable = require('./dist/cpexcel.js');
- out.length = k;
- return out.toString('ucs2');
+ return out.slice(0,k).toString('ucs2');
@loongdefect can you verify?
Maybe, Have you tested?
On Fri, May 12, 2017, 10:53 PM SheetJSDev [email protected] wrote:
I was unable to trip the issue by forcing strict mode in chrome. I think the following changes to xlsx resolves the issue in nodejs:
in bits/02_codepage.js https://github.com/SheetJS/js-xlsx/blob/master/bits/02_codepage.js#L5:
if(typeof cptable === 'undefined') cptable = require('./dist/cpexcel.js');+ if(typeof cptable === 'undefined') global.cptable = require('./dist/cpexcel.js');in bits/22_xmlutils.js https://github.com/SheetJS/js-xlsx/blob/master/bits/22_xmlutils.js#L116-L117 :
out.length = k;- return out.toString('ucs2');+ return out.slice(0,k).toString('ucs2');@loongdefect https://github.com/loongdefect can you verify?
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/SheetJS/js-xlsx/issues/324#issuecomment-301114801, or mute the thread https://github.com/notifications/unsubscribe-auth/AH3p8HYYOUv4YF6Uk9BAPkcTYA9wiJIYks5r5IBegaJpZM4GowH- .
From our (admittedly limited) tests, those two changes work with the xlsx nodejs script when called with the --use_strict option
While running my tests in Jest I am still getting this error ReferenceError: cptable is not defined. The stack trace as follows:
at make_xlsx (node_modules/react-export-excel/node_modules/xlsx/xlsx.js:10:44)
at Object.<anonymous> (node_modules/react-export-excel/node_modules/xlsx/xlsx.js:6:1)
at Object.<anonymous> (node_modules/react-export-excel/dist/ExcelPlugin/components/ExcelFile.js:19:13)
at Object.<anonymous> (node_modules/react-export-excel/dist/index.js:7:18)
at Object.<anonymous> (src/components/ExportList/ExportList.js:2:1)
I've tried npm install xlsx@latest and that didn't solve the problem.
0.18.5 版本依然存在这个问题,能解决一下吗,vite webpack 打包器 现在开发基本上都是严格模式
@Nidlow155 react-export-excel appears to be using its own fork, so please raise the issue with that project. The package.json for [email protected] lists
"xlsx": "git+https://github.com/securedeveloper/js-xlsx.git"
@Sunday9787 0.18.10 has the required package.json fields to play nice with vite.
- https://docs.sheetjs.com/docs/getting-started/installation/frameworks installation
- https://docs.sheetjs.com/docs/demos/bundler#vite complete ViteJS example
Since this thread is 7 years old and was closed and dormant for more than 5 years, we will be locking this issue. Please raise a new issue if there are further issues related to cptable.