I have created a NX plugin/lib named nx.
The plugin's package.json defines the linting target:
"lint": {
"executor": "#nrwl/linter:eslint",
"outputs": ["{options.outputFile}"],
"options": {
"lintFilePatterns": [
"libs/nx/executors.json",
"libs/nx/package.json",
"libs/nx/src/executors",
"libs/nx/src/generators"
]
}
}
The .eslintrc.json is:
{
"extends": ["../../.eslintrc.json"],
"ignorePatterns": ["!**/*"]
}
The extended .eslintrc.json is:
{
"root": true,
"ignorePatterns": ["**/*"],
"plugins": ["#nrwl/nx"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {
"#nrwl/nx/enforce-module-boundaries": [
"error",
{
"enforceBuildableLibDependency": true,
"allow": [],
"depConstraints": [
{
"sourceTag": "*",
"onlyDependOnLibsWithTags": ["*"]
}
]
}
]
}
},
{
"files": ["*.ts", "*.tsx"],
"extends": ["plugin:#nrwl/nx/typescript"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"extends": ["plugin:#nrwl/nx/javascript"],
"rules": {}
},
{
"files": "*.json",
"parser": "jsonc-eslint-parser",
"rules": {}
}
]
}
The problem is that the generator dir contains templates for generating ts apps and each app has its own .eslintrc.json file. So when I run linting for some reason it parses these files resulting in an error:
Failed to load config "../../.eslintrc.base.json" to extend from.
Referenced from:
[...]/libs/nx/src/generators/application/template/.eslintrc.json
I tried to update the ignorePatterns of my config
{
"ignorePatterns": ["!**/*", "**/*.eslintrc.json"]
}
but without success. How can I solve this problem?
I couldn't get rid of this SyntaxError: Cannot use import statement outside a module error no matter what I have tried and it got so frustrating.
Is there anybody out here solved this issue? I have read a million stackoverflow and github issue threads. No clear solutions.
The error I get is
Details:
/Users/brandi/Documents/workspaces/admin-v1/adminWebpack/vueSourceCode/test/__tests__/test.test.js:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,jest){import { shallowMount } from '#vue/test-utils';
^^^^^^
SyntaxError: Cannot use import statement outside a module
I have this setup:
jest.config.js
module.exports = {
moduleFileExtensions: [
'js', 'json', 'vue'
],
moduleNameMapper: {
'^~/(.*)$': '<rootDir>/vueSourceCode/$1',
'^#/(.*)$': '<rootDir>/vueSourceCode/$1'
},
modulePathIgnorePatterns: [
'<rootDir>/node_modules/',
'<rootDir>/build/',
'<rootDir>/config/'
],
transform: {
'^.+\\.js$': 'babel-jest',
'^[^.]+.vue$': 'vue-jest'
},
snapshotSerializers: [
'jest-serializer-vue'
],
testMatch: [
'<rootDir>/vueSourceCode/(tests/unit/**/*.spec.(js|jsx|ts|tsx)|**/__tests__/*.(js|jsx|ts|tsx))'
],
transformIgnorePatterns: [
'<rootDir>/node_modules/'
]
};
babelrc
{
"presets": [
"env",
"stage-2",
[
"#babel/preset-env",
{
"targets": {
"node": "current"
}
}
]
],
"env": {
"test": {
"plugins": [
"#babel/plugin-transform-modules-commonjs",
"#babel/plugin-transform-runtime"
]
}
},
"test": [
"jest"
]
}
Any idea on how to resolve this problem?
I need to compile a Managed C++ module in a Node.JS application. I read online that I need to enable CLI with the /clr flag, and set the msvs-settings and msbuild_settings attributes, it's still not working for me. I receive this error message:
cl : Command line error D8016: '/clr' and '/EHs' command-line options are incompatible [C:\MyProject\native-modules\encryption-utilities\addon\
build\encrypt.vcxproj]
I've gotten the information from this page:
https://github.com/nodejs/node-gyp/issues/568
Here is my binding.gyp.
Thank you.
{
"targets": [
{
"target_name": "encrypt",
'conditions': [
['OS=="mac"', {
"xcode_settings": {
"GCC_ENABLE_CPP_EXCEPTIONS": "YES",
"GCC_ENABLE_CPP_RTTI": "YES",
"OTHER_CFLAGS": ["-mmacosx-version-min=10.7", "-std=c++11", "-stdlib=libc++"],
"OTHER_CPLUSPLUSFLAGS": ["-mmacosx-version-min=10.7", "-std=c++11", "-stdlib=libc++"]
},
'defines': [
'LINUX_DEFINE',
'_MAC',
'_ULONGLONG',
],
"cflags": ["-Wall", "-std=c++11", '-fexceptions', '-Wno-writable-strings'],
"cflags!": ['-fno-exceptions', '-Wwritable-strings'],
"cflags_cc!": ['-fno-exceptions', '-Wwritable-strings'],
"cflags_cc": ['-fexceptions', '-Wno-writable-strings'],
"include_dirs": [
"/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include"
]
}],
['OS=="win"', {
'defines+': [
'WIN_DEFINE',
'INCLUDE_SIGNATURE_ENCRYPTION',
'WIN64',
'WIN32',
'_WIN32',
"_WIN32_WINNT=0x0601",
"_WINSOCK_DEPRECATED_NO_WARNINGS",
"_HAS_EXCEPTIONS=2",
"_SCL_SECURE_NO_WARNINGS",
"UNICODE",
"_UNICODE",
"_NO_ASYNCRTIMP",
"BOOST_ERROR_CODE_HEADER_ONLY"
],
'msbuild_toolset': 'v141',
{
'cflags_cc': [
'/clr'
],
}],
'msvs_settings': {
'VCCLCompilerTool': {
'RuntimeLibrary':'MultiThreadedDLL'
}
},
'msbuild_settings': {
'ClCompile': {
'CompileAsManaged':'true' # can be safe, pure
}
},
"include_dirs": [
"C:/Program Files (x86)/Windows Kits/10/Include/10.0.16299.0/shared",
],
# "run_as": {
# "action": ['C:/Program Files/nodejs/node.exe', '$(ProjectDir)/../../out/encrypt.js', ],
# },
"configurations": {
"Debug": {
'defines': [
'DEBUG',
'_DEBUG'
],
'library_dirs': [
],
},
"Release": {
'defines': [
'NDEBUG',
],
'library_dirs': [
],
}
},
"libraries": [
"crypt32.lib",
"winhttp.lib",
"httpapi.lib",
"bcrypt.lib",
"ws2_32.lib",
"iphlpapi.lib"
]
}]
],
"sources": [
"hello.cc",
"aes.cpp",
"base64.cpp",
"crypt.cpp",
"StringUtil.cpp"
],
"cflags": ["-Wall", "-std=c++11"],
"cflags!": ['-fno-exceptions'],
"cflags_cc!": ['-fno-exceptions'],
"include_dirs": [
"<!(node -e \"require('nan')\")",
"addon",
"addon/include",
"../addon/include",
"C:/Projects/C++/vcpkg/installed/x64-windows/include",
"include",
".."
]
},
{
"target_name": "copy_binary",
"type": "none",
"dependencies": ["encrypt"],
'conditions': [
[
'OS=="mac"', {
"copies": [
{
"destination": "<(module_root_dir)/mac/",
"files": ["<(module_root_dir)/build/Release/encrypt.node"]
}
],
}
],
[
'OS=="win"', {
'msbuild_toolset': 'v141',
{
'cflags_cc': [
'/clr'
],
}],
'msvs_settings': {
'VCCLCompilerTool': {
'RuntimeLibrary':'MultiThreadedDLL'
}
},
'msbuild_settings': {
'ClCompile': {
'CompileAsManaged':'true' # can be safe, pure
}
},
"configurations": {
"Debug": {
"copies": [
{
"destination": "<(module_root_dir)/win32/",
"files": ["<(module_root_dir)/build/Debug/encrypt.node", "<(module_root_dir)/build/Debug/encrypt.pdb"]
}
]
},
"Release": {
"copies": [
{
"destination": "<(module_root_dir)/win32/",
"files": ["<(module_root_dir)/build/Release/encrypt.node", "<(module_root_dir)/build/Release/encrypt.pdb"]
}
]
},
}
}
],
]
}
]
}
I don't know much about node.js or .gyp files, but I do know the error you are getting. D8016 means that "/clr implies /EHa, and you cannot specify any other /EH compiler option with /clr". The problem is likely to occur when you import old project files, or add /clr to an existing project.
The official way to fix it is open the offending .vcxproj project file in Visual Studio, navigate to the project Properties / Config Properties / C/C++ / Code Generation and change Enable C++ Exceptions from "Yes with extern C functions (/EHs)" to "Yes with SEH Exceptions (/EHa)".
To do it outside VS, open the .vcxproj file in any text (or xml) editor and either delete the lines:
<ExceptionHandling>SyncCThrow</ExceptionHandling>
or replace them with:
<ExceptionHandling>Async</ExceptionHandling>
I have a suite of tests are being run with jest.
- initFromProgressObject.test.js
- nodeifyProgressObject.test.js
- segments.test.js
- uuid.test.js
- volume.progress.test.js
- volume.segment.test.js
The command i use to run the tests is jest --notify. Here is the error I get in just 2 of the files:
/Users/bob/Developer/sedd/sedd-utils/src/tests/uuid.test.js:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import * as uuid from "../utils/uuid";
^^^^^^
SyntaxError: Unexpected token import
All of the files are using import, but only 2 of them are having this issue of Unexpected token import. On another question, I saw that it was important to set the env to test. I have tried that and it didn't change anything.
Here is my .babelrc:
{
"env": {
"es": {
"presets": [
[
"env",
{
"targets": {
"browsers": ["last 2 versions"],
"node": "current"
},
"modules": false
}
]
],
"ignore": ["**/*.test.js", "**/tests/*"]
},
"test": {
"presets": ["env"]
},
"cjs": {
"presets": [
[
"env",
{
"targets": {
"browsers": ["last 2 versions"],
"node": "current"
}
}
]
],
"ignore": ["**/*.test.js", "**/tests/*"]
}
}
}
The jest config is just the default.
Any ideas?
Goal: To be able to use es6 import, export default, etc...
What I have done is include a .babelrc file in the root of my project which contains:
{
"presets": ["env", "react", "stage-0", "stage-1"],
"plugins": ["transform-object-rest-spread"]
}
I looked at the docs on babel and for node it said that all I would have to do is include the preset "env" which I do, but when I try to do an statement like:
import { data } from './data'
I get an unexpected token error on the import statement, so I assume I am not doing something correctly.
Typical webpack.config.js
module: {
rules: [
{
test: /\.js$/,
use: 'babel-loader',
exclude: /node_modules/,
},
...
]
}
I suggest you update .babelrc to the following.
{
"presets": [
[
"env",
{
"modules": false,
"loose": true
}
],
"react"
],
"plugins": [
"transform-object-rest-spread"
]
}
for more goodies decorators / function binding / class props etc,
{
"presets": [
[
"env",
{
"modules": false,
"loose": true
}
],
"react"
],
"plugins": [
"transform-object-rest-spread",
"transform-function-bind",
"transform-class-properties",
"transform-decorators-legacy",
]
}