Nuxt:模块应该导出一个函数:@turf/helpers [ERROR]
Nuxt: Module should export a function: @turf/helpers [ERROR]
有人知道为什么我在 nuxt.config.js 中将 @turf/helpers
添加到我的 buildModules
时得到 Module should export a function: @turf/helpers
吗?
nuxt.config.js
// Plugins to run before rendering page: https://go.nuxtjs.dev/config-plugins
plugins: [
],
// Auto import components: https://go.nuxtjs.dev/config-components
components: true,
// Modules for dev and build (recommended): https://go.nuxtjs.dev/config-modules
buildModules: [
// https://go.nuxtjs.dev/tailwindcss
'@nuxtjs/tailwindcss',
'@turf/helpers'
],
// Modules: https://go.nuxtjs.dev/config-modules
modules: [
],
我是否将模块添加到了错误的数组中?
仅供参考:该模块存在于我的 package.json / 依赖项中。至此,安装成功。
// 组件 where import { point } from '@turf/helpers' returns undefined
<script>
import { defineComponent } from '@vue/composition-api';
import mapboxgl from 'mapbox-gl';
import { point } from '@turf/helpers'
export default defineComponent({
data () {
return {
geojson: {
'type': 'FeatureCollection',
'features': []
},
map: null,
}
},
mounted() {
this.initMapBox();
},
methods: {
// Initialize MapBox map
initMapBox: function() {
mapboxgl.accessToken = 'pk.eyJ1IjoiYWxleGFuZHJ1YW5hIiwiYSI6ImNrZTl3NzJ3bzIxNG4yc2w2aG03dHNkMDUifQ.xaSxrVMLZtfGAlWoGvB1PQ';
this.map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/alexandruana/cksxeq0637zjy17tcvd4h919d',
center: [22.253, 45.419],
zoom: 4
});
this.map.on('load', () => {
console.log('Map loaded.')
let point = point([22.253, 45.419]);
console.log(point)
this.map.addSource('points', {
type: 'geojson',
data: this.geojson
});
this.map.addLayer({
id: 'points',
type: 'circle',
source: 'points',
paint: {
'circle-radius': 8,
'circle-color': '#00a9e2'
},
filter: ['in', '$type', 'Point']
});
});
},
}
})
将其作为常规 NPM 包导入并在不与相同变量名冲突的情况下使用它解决了问题!
确实,这不是 Nuxt 模块。
有人知道为什么我在 nuxt.config.js 中将 @turf/helpers
添加到我的 buildModules
时得到 Module should export a function: @turf/helpers
吗?
nuxt.config.js
// Plugins to run before rendering page: https://go.nuxtjs.dev/config-plugins
plugins: [
],
// Auto import components: https://go.nuxtjs.dev/config-components
components: true,
// Modules for dev and build (recommended): https://go.nuxtjs.dev/config-modules
buildModules: [
// https://go.nuxtjs.dev/tailwindcss
'@nuxtjs/tailwindcss',
'@turf/helpers'
],
// Modules: https://go.nuxtjs.dev/config-modules
modules: [
],
我是否将模块添加到了错误的数组中?
仅供参考:该模块存在于我的 package.json / 依赖项中。至此,安装成功。
// 组件 where import { point } from '@turf/helpers' returns undefined
<script>
import { defineComponent } from '@vue/composition-api';
import mapboxgl from 'mapbox-gl';
import { point } from '@turf/helpers'
export default defineComponent({
data () {
return {
geojson: {
'type': 'FeatureCollection',
'features': []
},
map: null,
}
},
mounted() {
this.initMapBox();
},
methods: {
// Initialize MapBox map
initMapBox: function() {
mapboxgl.accessToken = 'pk.eyJ1IjoiYWxleGFuZHJ1YW5hIiwiYSI6ImNrZTl3NzJ3bzIxNG4yc2w2aG03dHNkMDUifQ.xaSxrVMLZtfGAlWoGvB1PQ';
this.map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/alexandruana/cksxeq0637zjy17tcvd4h919d',
center: [22.253, 45.419],
zoom: 4
});
this.map.on('load', () => {
console.log('Map loaded.')
let point = point([22.253, 45.419]);
console.log(point)
this.map.addSource('points', {
type: 'geojson',
data: this.geojson
});
this.map.addLayer({
id: 'points',
type: 'circle',
source: 'points',
paint: {
'circle-radius': 8,
'circle-color': '#00a9e2'
},
filter: ['in', '$type', 'Point']
});
});
},
}
})
将其作为常规 NPM 包导入并在不与相同变量名冲突的情况下使用它解决了问题!
确实,这不是 Nuxt 模块。