Vue introduces the local js file packaging error, but it is no problem to introduce the online version of js file in index.html?

For projects developed by

vue-cli, if you want to introduce viz.js, download online js files, VS Code will prompt the js with ts syntax when it is imported locally, so that it cannot be packaged and run . But the introduction of online viz.js into index.html bypasses the packaging problem and works instead.
can also be run directly when importing the local js file through the script tag in a normal project.
guess that the problem may be on the packaging.
what module should be installed for vue-cli to package and execute the js file with ts syntax?

online version: < script src= " https://cdn.bootcss.com/viz.j.;></script>
will report an error whenever the local file appears. The local js file is copied from the online version.

clipboard.png

ts
npmviz npm install viz -Snode_modules

clipboard.png

clipboard.png
index.js file? , fascinated


post an online link for viz.js and the introduced code.


1. Compare whether the local js file is consistent with the CDN file
2. You can add ts-loader
3 to the webpack configuration. See if viz.js has npm packages


indicates that its online version has been compiled into js.
npm downloads the ts source code. In general, publishing to npm should provide a packaged umd specification code. You can check the main attribute in the package.json in that package to see which file it points to. If it does point to the ts source code, then you have to add a plug-in for ts processing in the build/webpack.base.conf.js of your project, that is, the specific configuration of ts-loader, needs to check the documentation.

of course, the easiest thing is for you to download the online version of the code directly and use it as source code in your project


the question is bypassed. The current solution for
is to place the local viz.js in the static directory , and then introduce in index.html with the script tag.
although the viz.js file still displays syntax errors in VS Code, it does not affect packaging and running at this time.

The problem with

npm installing viz seems to be the wrong installation. It should be installing viz.js instead of viz .
after installing viz.js, you can find the code in the installed module, but VS Code still shows syntax errors.
as for references, er, trying to introduce files in import doesn't seem to work. npm is installed in version 2.0 , and the online version 2.0 doesn't seem to work either.

Menu