问题
I've added handsontable-pro, numbro, moment, pikaday and ZeroClipboard in my package.json
dependencies, e.g.:
"dependencies": {
"numbro": "^1.9.0",
"moment": "^2.14.1",
...
}
and imported these libraries in my angular1.5 app.ts
file like this:
import 'handsontable-pro';
import 'numbro';
import 'moment';
...
After running npm install
, npm run build
and also building and running my project, I'm getting the following error in the console of the developers tools of Chrome:
Uncaught Error: Cannot find module 'numbro'
at newRequire (handsontable.js:48)
at handsontable.js:55
at Object.23.cellTypes (handsontable.js:4238)
at newRequire (handsontable.js:53)
at handsontable.js:55
at Object.125.../node_modules/hot-builder/node_modules/handsontable/src/browser (handsontable.js:21831)
at newRequire (handsontable.js:53)
at outer (handsontable.js:61)
at handsontable.js:66
at handsontable.js:22
And also for the rest of the modules. Any ideas on that? Thank you.
回答1:
run this command
npm install angular-handsontable
this will install the required dependency.
https://handsontable.github.io/angular-handsontable/quick-start
回答2:
Some of these dependencies need to be exposed globally. If you are using webpack you can do it as follows:
module: {
rules: [
{
test: /(\.js)|(\.jsx)$/,
exclude: /node_modules/,
use: [{
loader: 'babel-loader',
options: {
presets: ['react', 'es2015']
}
}]
}, {
test: require.resolve('numbro'),
use: [{
loader: 'expose-loader',
options: 'numbro'
}]
}, {
test: require.resolve('moment'),
use: [{
loader: 'expose-loader',
options: 'moment'
}]
}, {
test: require.resolve('pikaday'),
use: [{
loader: 'expose-loader',
options: 'Pikaday'
}]
}, {
test: require.resolve('zeroclipboard'),
use: [{
loader: 'expose-loader',
options: 'ZeroClipboard'
}]
}
]
},
来源:https://stackoverflow.com/questions/43122567/handsontable-related-error-cannot-find-modules-numbro-moment-pikaday-zeroclip