javascript - webpack compiles the content in the backtick but reports an error, but I write the string directly and no error is reported
PHP中文网
PHP中文网 2017-05-19 10:28:09
0
3
837
const path = './../views/'
export default new Router({
  routes: [
    {
      path: '/',
      name: 'index',
      component: resolve => require([`${path}index`], resolve)
    }
  ]  

The above writing method will report an error

Error: Cannot find module './../views/index'.
    at webpackContextResolve (eval at 126 (10.js:6), <anonymous>:10:9)
    at webpackContext (eval at 126 (10.js:6), <anonymous>:5:29)
    at eval (eval at <anonymous> (app.js:962), <anonymous>:16:132)

But I changed it to component: resolve => require(['./../views/index'], resolve)No error will be reported, but in fact it is the same, please give an expert answer Why?

PHP中文网
PHP中文网

认证高级PHP讲师

reply all(3)
我想大声告诉你

The variables are in backticks... they are static in single quotes. This is the difference. Dynamic writing is not supported here

为情所困

Related to nodejs. Because there are two path forms for nodejs file import, one is to point to a js file, and the other is to point to a folder. When it is a folder, the index.js file in the folder will be referenced by default. Your path here is a folder. Since you don’t have an index.js file in it, an error will be reported. Of course you can also customize the file. You can create a new package.json file in this folder and write an object in it { main: "Write the name of the file you need to export by default" };

小葫芦

Has the question been solved

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template