问题详情:
用 npm install xls-to-json -g 全局安装
在项目里采用const xlsxj = require("xls-to-json") 引用
启动项目 : 项目可以正常启动,但是 下面有报错信息如下
ERROR in ./~/xls-to-json/~/xlsjs/dist/cpexcel.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./cptable in D:\software\WebStormWorkspaces\CS\node_modules\xls-to-json\node_modules\xlsjs\dist
@ ./~/xls-to-json/~/xlsjs/dist/cpexcel.js 805:16-41根据错误提示 打开 cpexcel.js 找到805行,代码如下
"use strict";
if(typeof cptable === "undefined") {
if(typeof require !== "undefined"){
var cpt = require('./cpt' + 'able');
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);我的安装目录图片为下:
安装目录里确实没有 cptable 文件问题来了,我换了很多个不同来源的包,安装了很多次,都没有这个文件,后台听朋友说 这个文件是动态生成的,为什么我的包里没有动态生成这个文件呢网上查看了很多资料,没有找个类似的情况,希望在这里能碰到有和我一样碰到这种情况的人,帮忙解答一下原因
先谢谢了
用 npm install xls-to-json -g 全局安装
在项目里采用const xlsxj = require("xls-to-json") 引用
启动项目 : 项目可以正常启动,但是 下面有报错信息如下
ERROR in ./~/xls-to-json/~/xlsjs/dist/cpexcel.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./cptable in D:\software\WebStormWorkspaces\CS\node_modules\xls-to-json\node_modules\xlsjs\dist
@ ./~/xls-to-json/~/xlsjs/dist/cpexcel.js 805:16-41根据错误提示 打开 cpexcel.js 找到805行,代码如下
"use strict";
if(typeof cptable === "undefined") {
if(typeof require !== "undefined"){
var cpt = require('./cpt' + 'able');
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);我的安装目录图片为下:
安装目录里确实没有 cptable 文件问题来了,我换了很多个不同来源的包,安装了很多次,都没有这个文件,后台听朋友说 这个文件是动态生成的,为什么我的包里没有动态生成这个文件呢网上查看了很多资料,没有找个类似的情况,希望在这里能碰到有和我一样碰到这种情况的人,帮忙解答一下原因
先谢谢了
第一种,在依赖中将:node_modules\xlsx-style\dist\cpexcel.js
js文件里,第807行,var cpt = require(’./cpt’ + ‘able’);有误,改成var cpt = cptable;就可以正确启动程序了第二种: 在webpack.base.conf.js 中重新编译module.exports = {
context: path.resolve(__dirname, '../'),
entry: {
app: './src/main.js'
},
output: {
path: config.build.assetsRoot,
filename: '[name].js',
publicPath: process.env.NODE_ENV === 'production'
? config.build.assetsPublicPath
: config.dev.assetsPublicPath
},
resolve: {
extensions: ['.js', '.vue', '.json'],
alias: {
'vue$': 'vue/dist/vue.esm.js',
'@': resolve('src'),
'static': resolve('static'),
'assets': resolve('src/assets')
},
},
[color=#FF6600]externals:{ './cptable': 'var cptable' },
module: {[/color]
=====================//////////////////////// 加行代码 externals:{ './cptable': 'var cptable' },
第一种,在依赖中将:node_modules\xlsx-style\dist\cpexcel.js
js文件里,第807行,var cpt = require(’./cpt’ + ‘able’);有误,改成var cpt = cptable;就可以正确启动程序了第二种: 在webpack.base.conf.js 中重新编译module.exports = {
context: path.resolve(__dirname, '../'),
entry: {
app: './src/main.js'
},
output: {
path: config.build.assetsRoot,
filename: '[name].js',
publicPath: process.env.NODE_ENV === 'production'
? config.build.assetsPublicPath
: config.dev.assetsPublicPath
},
resolve: {
extensions: ['.js', '.vue', '.json'],
alias: {
'vue$': 'vue/dist/vue.esm.js',
'@': resolve('src'),
'static': resolve('static'),
'assets': resolve('src/assets')
},
},
externals:{ './cptable': 'var cptable' },
module: {
=====================//////////////////////// 加行代码 externals:{ './cptable': 'var cptable' },