I was working on a WordPress plugin for a custom Gutenberg block.
Since I needed to add additional scripts which I wanted to write in TypeScript, I used "$ tsc --watch" and a "tsconfig.json"-file to compile them.
After installing #wordpress/scripts ("$ npm i --save-dev --save-exact #wordpress/scripts"), tsc indicated 89 errors at this path: node_modules#types\webpack\index.d.ts.
I have opened this file and found that the source of all the errors was the first line of this import statement:
import {
Tapable,
HookMap,
SyncBailHook,
SyncHook,
SyncLoopHook,
SyncWaterfallHook,
AsyncParallelBailHook,
AsyncParallelHook,
AsyncSeriesBailHook,
AsyncSeriesHook,
AsyncSeriesWaterfallHook,
} from 'tapable';
Tsc was still working for my files, but having 89 errors thrown each time I compile is concerning nonetheless.
This is the code of my tsconfig.json:
{
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"allowUnreachableCode": false,
"declaration": false,
"resolveJsonModule": true,
"experimentalDecorators": true,
"lib": [
"dom",
"es2017"
],
"moduleResolution": "node",
"module": "esnext",
"target": "es2017",
"outDir": "script/build",
"noUnusedLocals": true,
"noUnusedParameters": true,
"jsx": "react",
"jsxFactory": "h"
},
"include": [
"script/src"
],
"exclude": [
"node_modules"
]
}
I found that the problem was the path of the import statement.
Webpack was importing Tapable from node_modules/tapable when it would have needed to import it from node_modules/#types/tapable.
Changing the last line of the import statement fixed all errors:
} from '../tapable';
Related
I'm using Firebase Functions for my App. I installed these firebase functions on my PC but I can't use the following command:
Firebase deploy --only functions
I get the following error:
node_modules/google-gax/build/protos/iam_service.d.ts:17:23 - error TS2497: This module
can only be referenced with ECMAScript imports/exports by turning on the
'esModuleInterop' flag and referencing its default export.
17 import * as Long from 'long';
~~~~~~
node_modules/google-gax/build/protos/operations.d.ts:17:23 - error TS2497: This module
can only be referenced with ECMAScript imports/exports by turning on the
'esModuleInterop' flag and referencing its default export.
17 import * as Long from 'long';
~~~~~~
Found 2 errors in 2 files.
Errors Files
1 node_modules/google-gax/build/protos/iam_service.d.ts:17
1 node_modules/google-gax/build/protos/operations.d.ts:17
Error: functions predeploy error: Command terminated with non-zero exit code2
Does anyone know how to turn on this flag?
just add "skipLibCheck": true to your tsconfig.json as shown below:
"compilerOptions": {
"module": "commonjs",
"noImplicitReturns": true,
"noUnusedLocals": true,
"outDir": "lib",
"sourceMap": true,
"strict": true,
"target": "es2017",
"skipLibCheck": true
},
I'm trying to program arduino in vscode. The problem is that It's giving me weird header errors:
cannot open source file "avr/pgmspace.h" (dependency of "C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino\Arduino.h")
This is my arduino.json:
"board": "arduino:avr:uno"
}
This is my c_cpp_properties.json:
{
"configurations": [
{
"name": "Win32",
"includePath": [
"C:\\Program Files (x86)\\Arduino\\tools\\**",
"C:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\**"
],
"forcedInclude": [
"C:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\cores\\arduino\\Arduino.h"
],
"intelliSenseMode": "msvc-x64",
"compilerPath": "C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.16.27023/bin/Hostx64/x64/cl.exe",
"cStandard": "c11",
"cppStandard": "c++17"
}
],
"version": 4
}
It should recursively include all of the required libraries, and even if imanually try to add the path to avr/pgmspace.h or its directory, it keeps giving me the same errors.
How do I solve this error?
Based on the responses to this issue, I added "c:\\Program Files (x86)\\Arduino\\hardware\\tools\\avr\\avr\\**" to my include path in c_cpp_properties.json:
"includePath": [
"c:\\Program Files (x86)\\Arduino\\tools\\**",
"c:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\**",
"c:\\Program Files (x86)\\Arduino\\hardware\\tools\\avr\\avr\\**"
],
For anyone who stumbles here on a Mac, here is the config that works for me with the Uno:
{
"env": {
"arduino_path": "/Applications/Arduino.app/Contents/Java",
"arduino_avr_include_path": "${env:arduino_path}/hardware/arduino/avr",
"arduino_avr_include2_path": "${env:arduino_path}/hardware/tools/avr/avr/include",
"arduino_avr_compiler_path": "${env:arduino_path}/hardware/tools/avr/bin/avr-g++"
},
"configurations": [
{
"name": "Mac",
"defines": [
"ARDUINO=10810",
"__AVR_ATmega328P__",
"UBRRH"
],
"includePath": [
"${workspaceRoot}",
"${env:arduino_avr_include_path}/**",
"${env:arduino_avr_include2_path}/**"
],
"forcedInclude": [
"/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/Arduino.h"
],
"intelliSenseMode": "gcc-x64",
"cStandard": "c11",
"cppStandard": "c++11",
"compilerPath": "${env:arduino_compiler_path} -std=gnu++11 -mmcu=atmega328p"
}
],
"version": 4
}
The key to finding <avr/pgmspace.h> was the adding the hardware/tools/avr/avr/include path.
Defining ARDUINO=10810 was identified from the output of running Arduino: Verify with the verbose flag.
Defining __AVR_ATmega328P__ was added to allow proper IntelliSense completion of the raw register macros (e.g. _BV(), OCR0A, TIMSK0, etc.); the correct macro to define was identified based on the chip being an ATMEGA328P-PU and by inspection of the file hardware/tools/avr/avr/include/avr/io.h.
The compilerPath value looks wrong, although it is only used by the IDE and not for target compilation. The documentation says :
The absolute path to the compiler you use to build your project. The extension will query the compiler to determine the system include paths and default defines to use for IntelliSense.
In any case I recommend to configure it properly, I was able to remove
"${HOME}/.arduino15/packages/arduino/tools/avr-gcc/5.4.0-atmel3.6.1-arduino2/bin/../lib/gcc/avr/5.4.0/include",
"${HOME}/.arduino15/packages/arduino/tools/avr-gcc/5.4.0-atmel3.6.1-arduino2/bin/../lib/gcc/avr/5.4.0/include-fixed",
"${HOME}/.arduino15/packages/arduino/tools/avr-gcc/5.4.0-atmel3.6.1-arduino2/bin/../lib/gcc/avr/5.4.0/../../../../avr/include"
when setting
"compilerPath": "${HOME}/.arduino15/packages/arduino/tools/avr-gcc/5.4.0-atmel3.6.1-arduino2/bin/avr-g++ -std=gnu++11 -mmcu=atmega328p",
To figure out the exact compiler that is used turn on verbose logging in the output window:
File -> Preferences -> Settings -> Extensions -> Arduino configuration -> Log level -> verbose
which in this case also should help you figure out why the compiler does not pick up avr/pgmspace.h.
Here are my arduino.json
{
"board": "arduino:avr:uno",
"port": "/dev/ttyUSB0",
"sketch": "src/myproject.ino",
"output": "../build"
}
and c_cpp_properties.json
{
"env": {
"arduino.path": "${HOME}/.arduino15/packages/arduino",
"arduino.avr.include.path": "${env:arduino.path}/hardware/avr/1.6.23",
"arduino.avr.compiler.path": "${env:arduino.path}/tools/avr-gcc/5.4.0-atmel3.6.1-arduino2/bin/avr-g++",
"arduino.libraries.path": "${HOME}/arduino/sketchbook/libraries",
"dummy-last-line": "To allow the second to last line (e.g. the real last line) to always end with a comma"
},
"configurations": [
{
"name": "Linux",
"includePath": [
"./src",
"./test",
"../arduino_ci/cpp/unittest",
"${env:arduino.libraries.path}/SmartLCD",
"${env:arduino.libraries.path}/Chronos/src",
"${env:arduino.libraries.path}/Time",
"${env:arduino.libraries.path}/RTClib",
"${env:arduino.avr.include.path}/libraries/Wire/src",
"${env:arduino.avr.include.path}/cores/arduino",
"${env:arduino.avr.include.path}/variants/standard"
],
"browse": {
"path": [
"${workspaceFolder}/src"
],
"limitSymbolsToIncludedHeaders": true
},
"defines": [
"UBRRH"
],
"intelliSenseMode": "gcc-x64",
"compilerPath": "${env:arduino.avr.compiler.path} -std=gnu++11 -mmcu=atmega328p",
"cStandard": "c11",
"cppStandard": "c++11"
}
],
"version": 4
}
(the UBRRH define is for the Serial variable in HardwareSerial.h)
I want to transpile both typescript and sass to javascript and css respectively. At The moment running this tasks.json file transpiles my typescript to javascript:
{
"version": "0.1.0",
// The command is tsc. Assumes that tsc has been installed using npm install -g typescript
"command": "tsc",
// The command is a shell script
"isShellCommand": true,
// Show the output window only if unrecognized errors occur.
"showOutput": "silent",
// args is the HelloWorld program to compile.
"args": ["public/app/boot.ts"],
// use the standard tsc problem matcher to find compile problems
// in the output.
"problemMatcher": "$tsc"
}
I only need to specify boot.ts and it transpiles all .ts files to js. It might be because my boot.ts file imports all my ts files. Here is my boot.ts file:
import {bootstrap} from 'angular2/platform/browser'
import {HelloWorld} from './hello_world'
import {TodoApp} from './todo_app'
bootstrap(HelloWorld);
bootstrap(TodoApp);
I would like to add code into the tasks.json file that will transpile the sass to css.
Here is a code snippet of what I could do to only transpile my sass:
{
"version": "0.1.0",
"command": "node-sass",
"isShellCommand": true,
"args": ["styles.scss", "styles.css"]
}
How do I add that code snippet so that it transpiles both the sass and the typescript?
Also, Will I be wanting to add any new sass files to the args array in tasks.json as I create them?
you can't do this with the tsc command. use npm instead.
package.json
{
"scripts": {
"build": "tsc public/app/boot.ts && node-sass styles.scss styles.css"
}
}
tasks.json
{
"version": "0.1.0",
"command": "npm",
"isShellCommand": true,
"showOutput": "silent",
"args": ["-s", "run"],
"tasks": [{
"taskName": "build",
"problemMatcher": "$tsc",
"isBuildCommand": true
}]
}
I'm not sure when this feature was added, so it may not of helped the OP. I like this because it's built-in to the IDE. For the OP case they just need to decide which should be completed before the other.
The following snippet allows multiple tasks to be run, one after the other. A pre-build, build, and post-build, when building your project select the "Pre-Build & Build & Post-Build" to run them all. This is still a rather simple chain of tasks, and you could create multiple chains of any length with this technique, but they do tend to clutter up the tasks.json file.
"tasks": [
{
"label": "base",
"detail": "Pre-Build",
"type": "shell",
"command":["echo"],
"args": ["prebuild task"],
},
{
"label": "build",
"detail": "Pre-Build & Build",
"type": "shell",
"command":["echo"],
"args": ["build task"],
"dependsOn":["base"],
},
{
"label": "Post Build",
"detail": "Pre-Build & Build & Post-Build",
"type": "shell",
"command":["echo"],
"args": ["Post build task"],
"dependsOn":["build"],
}
]
In my karma.conf.js
plugins : [
'karma-phantomjs-launcher',
'karma-angular-filesort',
'karma-coverage',
'karma-jasmine',
'karma-ng-html2js-preprocessor',
'karma-spec-reporter',
],
coverageReporter: {
type : 'html',
dir : 'coverage/'
},
specReporter: {
maxLogLines: 10,
suppressPassed: false,
suppressFailed: false,
suppressSkipped: false,
suppressErrorSummary: false
},
// reporters: ['progress']
reporters: ['spec']
Yet when I run my tests (gulp test), the output continues to be the same as when karma used the 'progress' reporter.
What am I missing?
I've tried to follow all these other threads but am unable to get this to work for some reason:
Vendor CSS files not being compiled for Brunch
Separating app and vendor css in Brunch
For some reason, I'm unable to get brunch to ouput vendor CSS at all?
The particular package I'm talking about is Fancybox which has a css file source/jquery.fancybox.css.
I've overridden the fancybox main in my bower.json (as no main is included in the package). For some reason, no css is output, only the javascript. I feel like I must be doing something trivially wrong as no errors are output either and I even see the css file as being watched in the debug output?
Output of brunch b -Pd:
❯ brunch b -Pd > brunch-debug.txt
brunch:watch Loaded plugins: javascript-brunch, sass-brunch +0ms
brunch:watch File 'package.json' received event 'add' +5ms
brunch:watch File 'bower.json' received event 'add' +1ms
brunch:watch File 'brunch-config.coffee' received event 'add' +0ms
brunch:file-list Reading 'bower_components/fancybox/source/jquery.fancybox.js' +1ms
brunch:watch File 'bower_components/fancybox/source/jquery.fancybox.js' received event 'add' +0ms
brunch:file-list Reading 'bower_components/fancybox/source/jquery.fancybox.css' +0ms
brunch:watch File 'bower_components/fancybox/source/jquery.fancybox.css' received event 'add' +0ms
brunch:source-file Initializing fs_utils.SourceFile: {"path":"bower_components/fancybox/source/jquery.fancybox.js","isntModule":true,"isWrapped":true} +1ms
brunch:pipeline Compiling 'bower_components/fancybox/source/jquery.fancybox.js' with 'JavaScriptCompiler' +1ms
brunch:file-list Compiled file 'bower_components/fancybox/source/jquery.fancybox.js'... +40ms
brunch:write Writing 1/1 files +71ms
brunch:generate Concatenating bower_components/fancybox/source/jquery.fancybox.js to public/libraries.js +3ms
brunch:common Writing file 'public/libraries.js' +7ms
I've setup my config files so:
brunch-config.coffee
module.exports = config:
files:
javascripts: joinTo:
'libraries.js': /^(?!app\/)/
'app.js': /^app\//
stylesheets: joinTo:
'vendor.css': /^(bower_components|vendor)\//
'app.css': /^app\//
modules:
wrapper: false
definition: false
bower.json
{
"name": "brunch-test-fancybox",
"version": "0.0.0",
"authors": [
"Test <test#test.com>"
],
"description": "",
"main": "",
"moduleType": [],
"license": "MIT",
"homepage": "",
"private": true,
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"test",
"tests"
],
"overrides": {
"fancybox": {
"main": [
"source/jquery.fancybox.css",
"source/jquery.fancybox.js"
]
}
},
"dependencies": {
"fancybox": "~2.1.5"
}
}
package.json
{
"name": "brunch-test-fancybox",
"version": "1.0.0",
"description": "",
"main": "index.js",
"dependencies": {
"brunch": "^1.8.5",
"javascript-brunch": "^1.7.1",
"sass-brunch": "^1.9.1"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}
Add the css-brunch plugin to your project, otherwise Brunch does not know how you want to handle .css files.