问题描述
我使用 Nuxt,有时,当我想使用一些 npm 包时,会出现此错误:
SyntaxError
Unexpected token '<'
堆栈:
vm.js:102:7
new Script
internal/modules/cjs/loader.js:1114:10
Module._extensions..js
internal/modules/cjs/loader.js:950:32
Module.load
internal/modules/cjs/loader.js:790:14
Module._load
internal/modules/cjs/loader.js:974:19
Module.require
webpack:/external "vue-typeahead-bootstrap":1:
Object.vue-typeahead-bootstrap
webpack/bootstrap:25:
__webpack_require__
pages/account/tabs/addresses.js:693:81
Module../node_modules/babel-loader/lib/index.js?!./node_modules/vue-loader/lib/index.js?!./components/address/form/country.vue?vue&type=script&lang=js&
webpack/bootstrap:25:
例如我在这个包上有这个错误:vue-typeahead-bootstrap
如果我导入包:
import VueTypeaheadBootstrap from ['vue-typeahead-bootstrap'](https://github.com/mattzollinhofer/vue-typeahead-bootstrap)
export default {
components: { VueTypeaheadBootstrap },}
它抛出错误。
是因为不支持这个包还是什么?
解决方法
您可以尝试转译它。 https://nuxtjs.org/docs/2.x/configuration-glossary/configuration-build#transpile
像这样添加包名
{
build: {
transpile: [
({ isServer }) => 'vue-typeahead-bootstrap'
]
}
}
如此处回答:https://github.com/mattzollinhofer/vue-typeahead-bootstrap/issues/19#issuecomment-645510809