0

I have a simple Typescript project with this code:

import {
  parseComponent,
  compile as compileTemplate,
  ASTElement,
} from "vue-template-compiler";
...

I compile it using tsc with:

    "target": "es2020",
    "module": "commonjs",

And it gives code like this:

const vue_template_compiler_1 = require("vue-template-compiler");

In my package.json I have this:

  "dependencies": {
    "vue-template-compiler": "^2.6.12"

But I don't have "vue", because I don't need all of Vue - just the template compiler.

This all works fine, but I'm trying to use Webpack to bundle everyone into a single file. However, when I run webpack I get this error:

ERROR in ./node_modules/vue-template-compiler/index.js 2:19-41
Module not found: Error: Can't resolve 'vue' in '/path/to/myproject/node_modules/vue-template-compiler'
 @ ./build/analysis.js 8:32-64
 @ ./build/index.js 8:19-40

This corresponds to the require("vue-template-checker") line. Why do I get this error?

Here's my webpack.config.js:

const path = require("path");
const webpack = require("webpack");

module.exports = {
  target: "node",
  entry: "./build/index.js",
  mode: "production",
  output: {
    filename: "index.js",
    path: path.resolve(__dirname, "dist"),
  },
  plugins: [
    new webpack.BannerPlugin({ banner: "#!/usr/bin/env node", raw: true }),
  ],
};

1 Answer 1

1

That module makes Vue version check during import. I guess, you want to skip that check. I would try aliasing. Something like:

module.exports = {
  // ...
  resolve: {
    alias: {
      'vue-template-compiler$': 'vue-template-compiler/build.js'
    }
  }
}
Sign up to request clarification or add additional context in comments.

2 Comments

That worked, thanks! Where does it do the version check?
@Timmmm In package.json entryfile - index.js

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.