I am currently in the process of exporting a Vue component as a package, utilizing vue cli to build the distribution. My goal is to publish it on npm, but for testing purposes, I am using a symbolic link. Despite starting with a basic hello-world project, I am unable to create a valid package.
To begin, I created a project:
vue create hello-world
Next, I made modifications to the package.json file:
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build --target lib --name vue-hello-world ./src/components/HelloWorld.vue",
"lint": "vue-cli-service lint"
},
"main": "./dist/vue-hello-world.common.js",
After updating the script commands, I ran:
npm run build
The compilation process was successful without any errors.
However, when I attempted to import the packaged component into another Vue project (using a symbolic link in node_modules), I encountered the following error during page rendering:
[Vue warn]: Failed to resolve async component: function MediaViewerPdf() {
return Promise.all(/*! import() */[__webpack_require__.e(62), __webpack_require__.e(46)]).then(__webpack_require__.bind(null, /*! ./viewers/MediaViewerPdf.vue */ "./vuejs/components/mediaViewer/viewers/MediaViewerPdf.vue"));
}
Reason: ReferenceError: require is not defined
Any insights on what might be causing this issue?
Additional Notes:
- When running
vue inspect
, I confirmed that the webpack config has the line:
target: "web"
- I have already set resolve.symlinks to false in the importing project.
EDIT: It has been verified that the issue persists even when utilizing the package directly from node_modules, ruling out potential issues related to the symbolic link.
For the full code repository, please visit: https://github.com/louis-sanna/vue-hello-world