0
votes

I used vue ui to create a vue project with typescript, I then added electron, iview and less ...

I only corrected the lexical problems in the *.ts files but when I run the vue-cli-service serve task in vue ui, I get the following output :

Total task duration: 1191.84s
$ vue-cli-service serve --mode development --dashboard
 INFO  Starting development server...

Starting type checking and linting service...

 12% building modules 23/53 modules 30 active ...ode_modules/core-js/modules/_perform.jsUsing 1 worker with 2048MB memory limit

 85% chunk order optimization OccurrenceOrderChunkIdsPlugin ERROR  Failed to compile with 1 errors11:31:30 PM


 error  in ./src/iview-variables.less

Module build failed (from ./node_modules/less-loader/dist/cjs.js):


// https://github.com/ant-design/ant-motion/issues/44
.bezierEasingMixin();
^
Inline JavaScript is not enabled. Is it set in your options?
  in /Users/ailete619/landema_electron/node_modules/iview/src/styles/color/bezierEasing.less (line 110, column 0)

 @ ./src/iview-variables.less 4:14-226 14:3-18:5 15:22-234
 @ ./src/plugins/iview.js
 @ ./src/main.ts
 @ multi (webpack)-dev-server/client?http://192.168.179.4:8080/sockjs-node (webpack)/hot/dev-server.js ./src/main.ts

Type checking and linting in progress...

 WARN
Couldn't parse bundle asset  "/Users/ailete619/landema_electron/dist/about.js".
Analyzer will use module sizes from stats file.


WARNING in /Users/ailete619/landema_electron/src/background.ts
13:3 require statement not part of an import statement
    11 | if (isDevelopment) {
    12 |   // Don't load any native (external) modules until the following line is run:
  > 13 |   require('module').globalPaths.push(process.env.NODE_MODULES_PATH);
       |   ^
    14 | }
    15 | // global reference to mainWindow (necessary to prevent window from being garbage collected)
    16 | let mainWindow: any;    
No type errors found
Version: typescript 3.0.3, tslint 5.11.0
Time: 3084ms

I tried to modify the following lines, but I don't really understand their purpose so I get different errors but no solution :

if (isDevelopment) {
  // Don't load any native (external) modules until the following line is run:
  require('module').globalPaths.push(process.env.NODE_MODULES_PATH)
}

My question: How can I change that line to work with typescript?

PS: For the Module build failed error, I am working on it and will ask another question if necessary ...

Installed plugins:

  • @vue/cli-service version 3.01
  • @vue/cli-plugin-babel version 3.0.1
  • @vue/cli-plugin-pwa version 3.0.1
  • @vue/cli-plugin-typescript version 3.0.1
  • vue-cli-plugin-electron-builder version 1.0.0-rc2
  • vue-cli-plugin-iview version 1.0.6

Main dependencies :

  • iview version 3.1.0
  • register-service-worker version 1.5.2
  • vue version 2.5.17
  • vue-class-component version6.2.0
  • vue-property-decorator version 7.0.0
  • vue-router version 3.0.1
  • vuex version 3.0.1
  • electron version 2.0.8
  • less version 3.8.1
  • less-loader version 4.0.1
  • typescript version 3.0.3
  • vue-template-compiler version 2.5.17

Proposed solution 1: Breaking the statement in 2 raises new errors ...

ERROR in /Users/ailete619/landema_electron/src/background.ts
11:1 Import assignment cannot be used when targeting ECMAScript modules. Consider using 'import * as ns from "mod"', 'import {a} from "mod"', 'import d from "mod"', or another module format instead.
     9 | } from 'vue-cli-plugin-electron-builder/lib';
    10 | const isDevelopment = process.env.NODE_ENV !== 'production';
  > 11 | import module = require('module');
       | ^
    12 | if (isDevelopment) {
    13 |   // Don't load any native (external) modules until the following line is run:
    14 |   module.globalPaths.push(process.env.NODE_MODULES_PATH);
ERROR in /Users/ailete619/landema_electron/src/background.ts
14:10 Property 'globalPaths' does not exist on type 'typeof Module'.
    12 | if (isDevelopment) {
    13 |   // Don't load any native (external) modules until the following line is run:
  > 14 |   module.globalPaths.push(process.env.NODE_MODULES_PATH);
       |          ^
    15 | }
    16 | // global reference to mainWindow (necessary to prevent window from being garbage collected)
    17 | let mainWindow: any;

My solution: I deleted it and I only have the less related error left ... problem solved?

1

1 Answers

0
votes

Try this:

import module = require('module');
if (isDevelopment) {
  // Don't load any native (external) modules until the following line is run:
  module.globalPaths.push(process.env.NODE_MODULES_PATH)
}