api.targets is not a function in plugin-proposal-object-rest-spread - babeljs

I have this error when I try to compile my app. The error comes from babel-plugin-proposal-object-rest-spread here https://github.com/babel/babel/blob/6e551ae8827d064680c1344074db9fb3093967e9/packages/babel-plugin-proposal-object-rest-spread/src/index.js#L22 :
Trace: error TypeError: api.targets is not a function
| at /home/username/Documents/front-newlook/node_modules/next/node_modules/#babel/preset-env/node_modules/#babel/plugin-proposal-object-rest-spread/lib/index.js:38:25
| at /home/username/Documents/front-newlook/node_modules/next/node_modules/#babel/preset-env/node_modules/#babel/helper-plugin-utils/lib/index.js:19:12
| at /home/username/Documents/front-newlook/node_modules/next/node_modules/#babel/core/lib/config/full.js:166:14
| at cachedFunction (/home/username/Documents/front-newlook/node_modules/next/node_modules/#babel/core/lib/config/caching.js:32:19)
| at loadPluginDescriptor (/home/username/Documents/front-newlook/node_modules/next/node_modules/#babel/core/lib/config/full.js:201:28)
| at /home/username/Documents/front-newlook/node_modules/next/node_modules/#babel/core/lib/config/full.js:71:20
My babel.config.json is like this:
{
"plugins": [
"emotion",
"macros",
"#babel/plugin-proposal-class-properties"
],
"presets": ["next/babel"],
"env": {
"test": {
"plugins": ["require-context-hook"]
}
}
}
Does anyone has an idea? Thank you

The problem was solved when I removed the node_modules folder and then ran yarn install

Run "npm install" once, It will fix the issue.

Related

Unix pipe in NX project.json

Is it possible to pipe the output of an executor to a CLI command.
In package.json I would do this:
"dev": "node index.js | pino-pretty"
I cannot figure out how to apply this to the project.json
"dev": {
"executor": "#nrwl/node:node",
"options": {
"buildTarget": "api:build"
}
}
I managed to get it to work by creating a custom task:
"pretty": {
"command":"npx nx serve | pino-pretty"
},
"serve" ...
So now I use npx nx pretty myproject and that runs nx serve and pipes it to pino-pretty

Jest: Cannot use import statement outside a module

I got an error when I run test using Jest, I tried to fix this error for 2 hours. But, I couldn't fix it. My module is using gapi-script package and error is occurred in this package. However, I don't know why this is occurred and how to fix it.
jest.config.js
module.exports = {
"collectCoverage": true,
"rootDir": "./",
"testRegex": "__tests__/.+\\.test\\.js",
"transform": {
'^.+\\.js?$': "babel-jest"
},
"moduleFileExtensions": ["js"],
"moduleDirectories": [
"node_modules",
"lib"
]
}
babel.config.js
module.exports = {
presets: [
'#babel/preset-env',
]
};
methods.test.js
import methods, { typeToActions } from '../lib/methods';
methods.js
import { gapi } from "gapi-script";
...
Error Message
C:\haram\github\react-youtube-data-api\node_modules\gapi-script\index.js:1
({"Object.":function(module,exports,require,__dirname,__filename,global,jest){import
{ gapi, gapiComplete } from './gapiScript';
SyntaxError: Cannot use import statement outside a module
What is wrong with my setting?
As of this writing, Jest is in the process of providing support for ES6 modules. You can track the progress here:
https://jestjs.io/docs/en/ecmascript-modules
For now, you can eliminate this error by running this command:
node --experimental-vm-modules node_modules/.bin/jest
instead of simply:
jest
Be sure to check the link before using this solution.
I solved this with the help of Paulo Coghi's answer to another question -
Does Jest support ES6 import/export?
Step 1:
Add your test environment to .babelrc in the root of your project:
{
"env": {
"test": {
"plugins": ["#babel/plugin-transform-modules-commonjs"]
}
}
}
Step 2:
Install the ECMAScript 6 transform plugin:
npm install --save-dev #babel/plugin-transform-modules-commonjs
Jest needs babel to work with modules.
For the testing alone, you do not need jest.config.js, just name the testfiles xxx.spec.js or xxx.test.js or put the files in a folder named test.
I use this babel.config.js:
module.exports = function (api) {
api.cache(true)
const presets = [
"#babel/preset-env"
]
return {
presets
}
}
Adding "type": "module" in package.json or using mjs as stated in other answers is not necessary when your setup is not too complicated.
I have also faced the same issue and this was resolved by adding following command-line option as a environment variable.
export NODE_OPTIONS=--experimental-vm-modules npx jest //linux
setx NODE_OPTIONS "--experimental-vm-modules npx jest" //windows
Upgrading Jest (package.json) to version 29 (latest as of now) solved this problem for me.

TYPO3 CMS 8.7.27: Call to a member function getPackagePath() on null

After installing extensions in typo3 CMS 8.7.27, I got following error.. Seems like the ExtensionManagementUtility can't load the ah_contentapi.
This is my composer.json file in root (/var/www/html/typo3) for loading my extensions:
{
"repositories":[
{
"type":"composer",
"url":"https://composer.typo3.org/"
},
{
"type":"package",
"package":{
"name":"Bm/ah-content-api",
"version":"0.0.1",
"type":"typo3-cms-extension",
"source":{
"url":"https://user#bitbucket.org/company/ah_config_typo3.git",
"type":"git",
"reference":"master"
}
}
},
{
"type":"package",
"package":{
"name":"Bm/ah-contentelements",
"version":"0.0.1",
"type":"typo3-cms-extension",
"source":{
"url":"https://user#bitbucket.org/company/ah_contentelements_typo3.git",
"type":"git",
"reference":"master"
}
}
}
],
"name":"typo3/cms-base-distribution",
"description":"TYPO3 CMS Base Distribution",
"license":"GPL-2.0-or-later",
"require":{
"helhum/typo3-console":"^4.9.3 || ^5.2",
"typo3/cms-about":"^8.7.10",
"typo3/cms-belog":"^8.7.10",
"typo3/cms-beuser":"^8.7.10",
"typo3/cms-context-help":"^8.7.10",
"typo3/cms-documentation":"^8.7.10",
"typo3/cms-felogin":"^8.7.10",
"typo3/cms-fluid-styled-content":"^8.7.10",
"typo3/cms-form":"^8.7.10",
"typo3/cms-func":"^8.7.10",
"typo3/cms-impexp":"^8.7.10",
"typo3/cms-info":"^8.7.10",
"typo3/cms-info-pagetsconfig":"^8.7.10",
"typo3/cms-rte-ckeditor":"^8.7.10",
"typo3/cms-setup":"^8.7.10",
"typo3/cms-sys-note":"^8.7.10",
"typo3/cms-t3editor":"^8.7.10",
"typo3/cms-tstemplate":"^8.7.10",
"typo3/cms-viewpage":"^8.7.10",
"typo3/cms-wizard-crpages":"^8.7.10",
"typo3/cms-wizard-sortpages":"^8.7.10",
"typo3/cms":"^8.7",
"dmitryd/typo3-realurl":"2.*",
"GridElementsTeam/Gridelements":"8.2.*",
"clickstorm/cs_seo":"3.*",
"Bm/ah-content-api":"0.0.1",
"Bm/ah-contentelements":"0.0.1"
},
"scripts":{
"typo3-cms-scripts":[
"typo3cms install:fixfolderstructure",
"typo3cms install:generatepackagestates"
],
"post-autoload-dump":[
"#typo3-cms-scripts"
]
},
"extra":{
"typo3/cms":{
"web-dir":"public"
},
"helhum/typo3-console":{
"comment":"This option is not needed ay more for helhum/typo3-console 5.x",
"install-extension-dummy":false
}
},
"autoload":{
"psr-4":{
"Bm\\AhContentelements\\":"public/typo3conf/ext/ah_contentelements/Classes",
"Bm\\AhContentapi\\":"public/typo3conf/ext/ah_content_api/Classes"
}
}
}
I already cleared cache in install tool at:
1. -> important actions -> clear all cache
2. -> clean up -> Clean typo3temp/ folder
piece from composer.lock:
{
"_readme": [
"This file locks the dependencies of your project to a known state",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is #generated automatically"
],
"content-hash": "954afd2318d54ec9b1dd0e4d7f9b445b",
"packages": [
{
"name": "Bm/ah-content-api",
"version": "0.0.1",
"source": {
"type": "git",
"url": "https://stevenhippovibe#bitbucket.org/hippovibe/ah_config_typo3.git",
"reference": "master"
},
"type": "typo3-cms-extension"
},
{
"name": "Bm/ah-contentelements",
"version": "0.0.1",
"source": {
"type": "git",
"url": "https://stevenhippovibe#bitbucket.org/stevenhippovibe/ah_contentelements_typo3.git",
"reference": "master"
},
"type": "typo3-cms-extension"
},
The Error occurs when the extension folder name under typo3conf/ext/<folder_name> doesn't match extension key used in some places of the system (e.g. using EXT:your_extension_key/... syntax in TypoScript).
Changing folder name fixed similar problem for me.
Check the PHP version and try to change it from i.e. 7.4 to 7.3.
I once had this problem with an extension that should be compatible with PHP 7.4, but wasn't in real life. This solved the problem for me.
Question here is:
How did you update to 8.7.27 (which composer command was executed)
How does your composer.lock look like?
Do you use TYPO3 console or any other special composer plugins / CLI commands to e.g. generate PackageStates.php?
I just ran into the same error message under TYPO3 9.5.5.
Solution:
Deinstall one TYPO3 extension after the other and try it out again. This will lead you to the extension which has an error. Most probably the error is inside of the file ext_localconf.php or ext_tables.php .
I got this error detail:
PHP Warning: Use of undefined constant FH_DEBUG_EXT - assumed 'FH_DEBUG_EXT' (this will throw an Error in a future version of PHP) in /var/www/html/global-extensions/ext/div2007/ext_localconf.php line 15
This has nothing to do with your error. But it can be that you have an error in one of your installed extensions or even in a backup of an extension, e.g. a folder named as extensionname.bak .
Also these recommendations can help:
https://wiki.typo3.org/Exception/CMS/1476107295

How to run jsdoc on directory ignore .gitignore files

I can run jsdoc on a whole project with
$ jsdoc -r .
However this generates docs for js files inside node_modules. How can I tell jsdoc not run on files in .gitignore?
How about using a config file such as this one?
$ jsdoc.js -c ./.jsdoc.conf.json
./.jsdoc.conf.json
{
"source": {
"include": ["."],
"includePattern": ".+\\.js(doc|x)?$",
"excludePattern": "node_modules"
}
}
Borrowed from Generate jsdoc documentation here on Stack.
{
"source": {
"include": ["."],
"includePattern": ".(jsx|js|ts|tsx)$",
"exclude": [
"node_modules",
"docs"
]
}
}

Error running CoffeeScript in Sublime Text 2

I am new to both CoffeeScript and Sublime Text 2, so any help would be greatly appreciated.
When I try to compile a CoffeeScript test file in Sublime, I get the following error message:
[Error 2] The system cannot find the file specified
[cmd: [u'coffee', u'-c', u'C:\\Users\\username\\Desktop\\test.coffee']]
[dir: C:\Users\username\Desktop]
[path: $HOME/bin:/usr/local/bin:$HOME/bin:/usr/local/bin:C:\Program Files (x86)\ImageMagick-6.9.1-Q16;C:\ProgramData\Oracle\Java\javapath;C:\Program Files\Java\jdk1.8.0_25\bin;C:\Java\bin;C:\Program Files (x86)\Windows Live\Shared;C:\Program Files\nodejs\;C:\Program Files (x86)\GnuWin32\bin;C:\Program Files (x86)\Heroku\bin;C:\Program Files (x86)\git\cmd;C:\Program Files (x86)\Skype\Phone\;C:\RailsInstaller\Git\cmd;C:\RailsInstaller\Ruby2.1.0\bin;C:\Users\username\AppData\Roaming\npm]
[Finished]
Here are my build settings in commands:
{
"path": "$HOME/bin:/usr/local/bin:$PATH",
"cmd": ["coffee","-c","$file"],
"file_regex": "^(...*?):([0-9]*):?([0-9]*)",
"selector": "source.coffee, source.litcoffee, source.coffee.md"
}
Any idea how to fix this problem? Thanks.
I managed to get it working with the following code in the build file:
{
"cmd": [ "coffee", "-m", "-c", "$file" ],
"file_regex": "^(...*?):([0-9]*):?([0-9]*)",
"selector": "source.coffee, source.litcoffee, source.coffee.md",
"windows":
{
"shell": true
}
}