【问题标题】:How to use downloaded nodeModule library locally on my Vue project如何在我的 Vue 项目中本地使用下载的 nodeModule 库
【发布时间】:2018-12-13 11:08:51
【问题描述】:

我正在尝试使用通过 NPM 下载的本地库(例如 draggable-vue-directive ),并且我想在本地项目中使用它。

在我的 Vue 项目中,当它在我的 node_modules 项目文件夹中时,我确实通过这种方式导入它:

import { Draggable } from 'draggable-vue-directive'

如果该库在本地提供,我该如何使用它? 我试着做

import { Draggable } from '../myLibsFolder/draggable-vue-directive'

但是我收到了这个错误( ReferenceError: exports is not defined ) 它没有正确使用库。我只是将库复制到本地文件夹并尝试导入它,但我不能...

【问题讨论】:

  • 尝试在复制的模块中运行npm install。假设您的相对路径到达正确的位置,您正在以正确的方式使用该模块。检查库使用的启动文件的 package.json 文件,并尝试将导入指向那里,例如/lib 之类的子文件夹
  • 尝试将其更改为module.exports.Draggable = {...}

标签: javascript vue.js


【解决方案1】:

由于您使用的是import,您可以执行以下操作。

const draggable = {
 // Your code here
}

export default draggable

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-17
    • 1970-01-01
    • 2023-03-28
    • 1970-01-01
    相关资源
    最近更新 更多