I'm following this book: https://github.com/manfredsteyer/schematics-sample
When I execute my schematics
schematics .:my-comp
I get the following error:
An error occured:
Error: Schematic "my-comp" cannot resolve the factory.
at NodeModulesEngineHost.createSchematicDescription (/home/.../.npm-global/lib/node_modules/#angular-devkit/schematics-cli/node_modules/#angular-devkit/schematics/tools/file-system-engine-host-base.js:174:19)
at SchematicEngine.createSchematic (/home/.../.npm-global/lib/node_modules/#angular-devkit/schematics-cli/node_modules/#angular-devkit/schematics/src/engine/engine.js:219:38)
at CollectionImpl.createSchematic (/home/.../.npm-global/lib/node_modules/#angular-devkit/schematics-cli/node_modules/#angular-devkit/schematics/src/engine/engine.js:69:29)
at NodeWorkflow.execute (/home/.../.npm-global/lib/node_modules/#angular-devkit/schematics-cli/node_modules/#angular-devkit/schematics/src/workflow/base.js:99:38)
at main (/home/.../.npm-global/lib/node_modules/#angular-devkit/schematics-cli/bin/schematics.js:202:24)
at Object.<anonymous> (/home/.../.npm-global/lib/node_modules/#angular-devkit/schematics-cli/bin/schematics.js:293:5)
at Module._compile (internal/modules/cjs/loader.js:701:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
at Module.load (internal/modules/cjs/loader.js:600:32)
at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
This is part of my factory:
export default function myComp(options: IFlexComponentOptions): Rule {
return (host: Tree, context: SchematicContext) => {
console.log("options before sanatize", options);
...
return rule(host, context);
};
}
my collectyion.json
{
"$schema": "../node_modules/#angular-devkit/schematics/collection-schema.json",
"schematics": {
"my-comp": {
"description": "This schematics generate an Angular Component on the current module or in an specified one",
"factory": "./my-comp/index#myComp"
}
}
}
I had the same problem, from export default function myComp remove the default. And it should work. I follow the same book. Lots of incompatibilities.
For those who doesn't use default and has the same issue, please check the hash name versus the function name in the index file.
Related
Completely new to this stuff. Trying to deploy an NFT for my bachelor's thesis in a non-technical field.
I've been following this guide:
https://www.freecodecamp.org/news/how-to-make-an-nft/
And it's been going pretty well up until the point where I'm supposed to deploy the NFT and edit the HardHat config file to compile everything.
The guide has been using the "ropsten" network while I'm using rinkeby. Is that the problem?
This is my HardHat config file:
require("dotenv").config();
require("#nomiclabs/hardhat-ethers");
module.exports = {
solidity: "0.8.0",
defaultNetwork: "rinkeby",
networks: {
hardhat: {},
rinkeby: {
url: process.env.https://eth-rinkeby.alchemyapi.io/v2/MYURLCODE,
accounts: [`0x${process.env.MYPRIVATEKEY}`],
},
},
};
And this is my error message:
MYNAME#Ivans-MacBook-Pro ethereum % npx hardhat compile
An unexpected error occurred:
/Users/MYNAME/nft-project/ethereum/hardhat.config.js:10
url: process.env.https://eth-rinkeby.alchemyapi.io/v2/MYURL,
^
SyntaxError: Unexpected token ':'
at Object.compileFunction (node:vm:352:18)
at wrapSafe (node:internal/modules/cjs/loader:1033:15)
at Module._compile (node:internal/modules/cjs/loader:1069:27)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at importCsjOrEsModule (/Users/MYNAME/nft-project/ethereum/node_modules/hardhat/src/internal/core/config/config-loading.ts:28:20)
at loadConfigAndTasks (/Users/MYNAME/nft-project/ethereum/node_modules/hardhat/src/internal/core/config/config-loading.ts:80:18)
Would be incredibly grateful for any help!
by looking at the snippet i guess this line url: process.env.https://eth-rinkeby.alchemyapi.io/v2/MYURLCODE should become:
url: `https://eth-rinkeby.alchemyapi.io/v2/${process.env.MYURLCODE}`
assuming that your MYURLCODE env variable contains the correct value.
On my computer it works fine, but when I try to host it on Heroku it gives this error
/app/node_modules/slash-create/lib/command.js:21
throw new Error('The base SlashCommand cannot be instantiated.');
^
Error: The base SlashCommand cannot be instantiated.
at new SlashCommand (/app/node_modules/slash-create/lib/command.js:21:19)
at new module.exports (/app/commands/back.js:5:9)
at SlashCreator.registerCommand (/app/node_modules/slash-create/lib/creator.js:64:23)
at SlashCreator.registerCommands (/app/node_modules/slash-create/lib/creator.js:105:18)
at SlashCreator.registerCommandsIn (/app/node_modules/slash-create/lib/creator.js:132:21)
at Object. (/app/index.js:39:6)
at Module._compile (internal/modules/cjs/loader.js:1072:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)
at Module.load (internal/modules/cjs/loader.js:937:32)
at Function.Module._load (internal/modules/cjs/loader.js:778:12)
You are trying to register the base SlashCommand class as a command. You have to extend off of the class and add options to your command.
const { SlashCommand, CommandOptionType } = require('slash-create');
module.exports = class HelloCommand extends SlashCommand {
constructor(creator) {
super(creator, {
name: 'hello',
description: 'Says hello to you.',
options: [{
type: CommandOptionType.STRING,
name: 'food',
description: 'What food do you like?'
}]
});
this.filePath = __filename;
}
async run(ctx) {
return ctx.options.food ? `You like ${ctx.options.food}? Nice!` : `Hello, ${ctx.user.username}!`;
}
}
slash-create Example commands
slash-create template (with Heroku button)
I have an existing project, I used React 16.9. Now, I want to implement Gulp 4.0.1 to build it in the server. I am running in windows 10.
In my components, I am using import form
I tried using this gulpfile.js, its very simple.
var gulp = require('gulp'),
browserify = require('browserify'),
source = require('vinyl-source-stream'),
buffer = require('vinyl-buffer');
var BUILD_DIR = 'buildtest/';
function compile() {
var bundler = browserify('src/index.js');
return bundler
.transform('babelify', { presets: ['es2015', 'react'] })
.bundle()
.pipe(source('index.js'))
.pipe(buffer())
.pipe(gulp.dest(BUILD_DIR));
}
gulp.task('build:js', function() {
return compile();
})
gulp.task('build', ['build:js'])
Now by running the gulp command it gives me this error:
λ gulp
assert.js:350
throw err;
^
AssertionError [ERR_ASSERTION]: Task function must be specified
at Gulp.set [as _setTask] (D:\myprojectfolderpath\node_modules\undertaker\lib\set-task.js:10:3)
at Gulp.task (D:\myprojectfolderpath\node_modules\undertaker\lib\task.js:13:8)
at Object.<anonymous> (D:\myprojectfolderpath\gulpfile.js:84:6)
at Module._compile (internal/modules/cjs/loader.js:701:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
at Module.load (internal/modules/cjs/loader.js:600:32)
at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
at Function.Module._load (internal/modules/cjs/loader.js:531:3)
at Module.require (internal/modules/cjs/loader.js:637:17)
at require (internal/modules/cjs/helpers.js:22:18)
According to the gulp's task Documentation gulp.task([taskName], taskFunction) second argument the 'taskFunction' needs to use either a gulp.series() or gulp.parallel.
Before 4.0 it was possible to define the task as you did, but this changed in 4.0.
Changing your gulp.task('build', ['build:js']) into gulp.task('build', gulp.series('build:js')) should fix the issue.
I'm trying to get Netlify Functions work with Go.
First, I tried cloning official example repo (https://github.com/netlify/aws-lambda-go-example) and it worked.
My problem is, I have a Hugo website which require hugo build command and I don't know how to build Hugo with hugo and Go source files with make build (like in example repo) - I think it could solve the problem, but I couldn't find relevant docs describing this option.
So my next step was to manually compile Go function file and put it into functions folder.
source file (from the example above):
package main
import (
"github.com/aws/aws-lambda-go/events"
"github.com/aws/aws-lambda-go/lambda"
)
func handler(request events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {
return events.APIGatewayProxyResponse{
StatusCode: 200,
Body: "Hello AWS Lambda and Netlify",
}, nil
}
func main() {
// Make the handler available for Remote Procedure Call by AWS Lambda
lambda.Start(handler)
}
I used instruction available at https://github.com/aws/aws-lambda-go#building-your-function to compile Go binary:
GOOS=linux GOARCH=amd64 go build -o hello hello.go
zip hello.zip hello
mv hello.zip ./functions/hello.zip
This was pushed to Git and therefore deployed to Netlify. So far so good, my function appeared in Netlify UI.
But when I requested the function URL, I got error message:
{
"errorMessage": "Invalid or unexpected token",
"errorType": "SyntaxError",
"stackTrace": [
"",
"SyntaxError: Invalid or unexpected token",
"createScript (vm.js:80:10)",
"Object.runInThisContext (vm.js:139:10)",
"Module._compile (module.js:616:28)",
"Object.Module._extensions..js (module.js:663:10)",
"Module.load (module.js:565:32)",
"tryModuleLoad (module.js:505:12)",
"Function.Module._load (module.js:497:3)",
"Module.require (module.js:596:17)",
"require (internal/module.js:11:18)"
]
}
This is function log from Netlify:
1:18:16 AM: hello invoked
1:18:17 AM: Syntax error in module 'hello': SyntaxError
(function (exports, require, module, __filename, __dirname) { ELF
^
SyntaxError: Invalid or unexpected token
at createScript (vm.js:80:10)
at Object.runInThisContext (vm.js:139:10)
at Module._compile (module.js:616:28)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
1:19:02 AM: hello invoked
1:19:03 AM: Syntax error in module 'hello': SyntaxError
^
SyntaxError: Invalid or unexpected token
at createScript (vm.js:80:10)
at Object.runInThisContext (vm.js:139:10)
at Module._compile (module.js:616:28)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
Also, function name appears to be hello.js in Netlify UI - I don't know if it should be like that. It seems to me that AWS thinks it's Javascript instead of Go.
I have not tested a zipped go function on Netlify.
If you do not want to do the manual build in this case, you can inline your build commands on Netlify deploy.
Add a build command that does both builds for the project.
[build]
command = "make build && hugo"
functions = "functions"
publish = "public"
[build.environment]
# Change this path with the path to your repository
GO_IMPORT_PATH = "github.com/netlify/aws-lambda-go-example"
I have a component that loads styles like this. The css directory is somewhere else; here it is being used as a Webpack alias.
import 'css/components/PromptText';
// ...
class PromptText extends React.Component {
// ...
}
Here is my webpack.config.json:
var path = require('path');
module.exports = {
entry: './src/index.jsx',
output: {
path: 'dist',
filename: 'app.bundle.js',
},
module: {
loaders: [{
test: /\.jsx?$/,
exclude: /node_modules/,
loader: 'babel',
}, {
test: /\.json/,
exclude: /node_modules/,
loader: 'json',
}, {
test: /\.scss/,
exclude: /node_modules/,
loaders: ['style', 'css', 'sass'],
}],
},
resolve: {
alias: {
css: 'css', // <-- Alias here
},
root: path.resolve(__dirname),
extensions: ['', '.js', '.jsx', '.scss'],
},
};
Now, I have a test like this for Mocha:
import PromptText from '../../src/components/PromptText';
describe('PromptText', () => {
it('should display words');
});
When Mocha imports the component, it also tries to load the CSS component. There are two problems with this:
The css directory has been aliased. Mocha needs to know where the alias points. To fix this, I have installed the babel-plugin-webpack-alias package, with the following .babelrc:
{
"presets": ["es2017", "react", "stage-0"],
"env": {
"test": {
"plugins": [
["webpack-alias", {"config": "webpack.config.js"}]
]
}
}
}
CSS can't be imported by Mocha, so it needs to be ignored. I use the ignore-styles package and invoke Mocha as mocha --compilers js:babel-core/register --require ignore-styles.
Despite having done these two things, I get the following error when trying to run tests:
(cd data && make)
make[1]: Nothing to be done for `all'.
NODE_ENV=test ./node_modules/.bin/mocha --compilers js:babel-core/register --require ignore-styles \
$(find test -type f -name 'test*.js')
module.js:341
throw err;
^
Error: Cannot find module 'css'
at Function.Module._resolveFilename (module.js:339:15)
at Function.Module._load (module.js:290:25)
at Module.require (module.js:367:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/Users/waleed/Workspace/js/steno/src/components/PromptText.jsx:2:1)
at Module._compile (module.js:413:34)
at loader (/Users/waleed/Workspace/js/steno/node_modules/babel-register/lib/node.js:146:5)
at Object.require.extensions.(anonymous function) [as .jsx] (/Users/waleed/Workspace/js/steno/node_modules/babel-register/lib/node.js:156:7)
at Module.load (module.js:357:32)
at Function.Module._load (module.js:314:12)
at Module.require (module.js:367:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/Users/waleed/Workspace/js/steno/test/components/testPromptText.js:2:1)
at Module._compile (module.js:413:34)
at loader (/Users/waleed/Workspace/js/steno/node_modules/babel-register/lib/node.js:146:5)
at Object.require.extensions.(anonymous function) [as .js] (/Users/waleed/Workspace/js/steno/node_modules/babel-register/lib/node.js:156:7)
at Module.load (module.js:357:32)
at Function.Module._load (module.js:314:12)
at Module.require (module.js:367:17)
at require (internal/module.js:20:19)
at /Users/waleed/Workspace/js/steno/node_modules/mocha/lib/mocha.js:220:27
at Array.forEach (native)
at Mocha.loadFiles (/Users/waleed/Workspace/js/steno/node_modules/mocha/lib/mocha.js:217:14)
at Mocha.run (/Users/waleed/Workspace/js/steno/node_modules/mocha/lib/mocha.js:485:10)
at Object.<anonymous> (/Users/waleed/Workspace/js/steno/node_modules/mocha/bin/_mocha:403:18)
at Module._compile (module.js:413:34)
at Object.Module._extensions..js (module.js:422:10)
at Module.load (module.js:357:32)
at Function.Module._load (module.js:314:12)
at Function.Module.runMain (module.js:447:10)
at startup (node.js:148:18)
at node.js:405:3
make: *** [test] Error 1
For some reason, the css alias isn't being resolved. However, this error only happens sometimes, unpredictably. In order to consistently recreate this error, I have to set BABEL_DISABLE_CACHE=1 in the environment.
How can I get my Mocha test to correctly import and ignore the CSS file?
In order to fix this, I switched from the babel-plugin-webpack-alias to the babel-plugin-webpack-aliases package, and update my .babelrc to use it:
{
"presets": ["es2017", "react", "stage-0"],
"env": {
"test": {
"plugins": [
["webpack-aliases", {"config": "webpack.config.js"}]
]
}
}
}
I also always run mocha with BABEL_DISABLE_CACHE=1 set in the environment. (I think this is undoing the damage that babel-plugin-webpack-alias did; it may not be necessary on every run if that package was never used.)